8000 Update Readme · instruct-rb/attributed-string@16e73c6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 16e73c6

Browse files
committed
Update Readme
1 parent a985915 commit 16e73c6

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

README.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
# AttributedString
22

3-
An attributed string implementation for Ruby.
3+
An attributed string implementation for Ruby. [![Ruby Tests](https://github.com/instruct-rb/attributed-string/actions/workflows/ruby.yml/badge.svg)](https://github.com/instruct-rb/attributed-string/actions/workflows/ruby.yml)
44

5-
An attributed string contains key-value pairs known as attributes that specify additional information related to ranges of characters within the string. Attributed strings support any key-value pair, but are often used for:
5+
An attributed string contains key-value pairs known as attributes that specify additional information related to ranges of characters within the string. Attributed strings support any key-value pair, but are often used for:
66

77
- Rendering attributes such as font, color, and other details.
8-
- Attributes for inline-attachments such as images, videos, files, etc.
8+
- Attributes for inline-attachments such as images, videos, files, etc.
99
- Semantic attributes such as link URLs or tool-tip information
10-
- Language attributes to support automatic gender agreement or verb agreement.
10+
- Language attributes to support automatic gender agreement or verb agreement.
1111
- Accessibility attributes that provide information for assistive technologies
1212
- Custom attributes you define
1313

14-
You will typically need to create a presenter for an attributed string, as the default shows no attribute information and inspect shows all attributes.
14+
You will typically need to create a presenter for an attributed string, as the default shows no attribute information and inspect shows all attributes.
15+
16+
This gem is inspired by Apple's [NSAttributedString](https://developer.apple.com/documentation/foundation/nsattributedstring)
1517

1618
## Installation
1719

1820
Add this line to your application's Gemfile:
1921

2022
```ruby
21-
gem 'attributed-string', github: 'instruct-rb/attributed-string', branch: 'main'
23+
gem 'attributed-string'
2224
```
2325

2426

@@ -30,16 +32,35 @@ Add this line to your application's Gemfile:
3032
using AttributedString::Refinements
3133
hello_world1 = AttributedString.new('Hello, World!', color: :red, font: 'Helvetica' )
3234
hello_world2 = 'Hello, World!'.to_attr_s(color: :red, font: 'Helvetica')
33-
puts hello_world1 == hello_world2 # true
35+
puts hello_world1 == hello_world2
36+
# => true
37+
38+
hello_world1.add_attrs(0..4, color: :blue)
39+
hello_world1 += "!!"
40+
puts hello_world1.inspect
41+
# => { color: blue, font: "Helvetica" }Hello{ color: red}, World!{ -color, -font}!!
42+
43+
puts hello_world1.attrs_at(0)
44+
# { color: blue, font: "Helvetica" }
3445
```
3546

3647
## Attachments
3748

3849
```ruby
3950
hello_world = AttributedString.new('Hello, World!')
51+
52+
# adding an attachment inserts the object character into the string
4053
hello_world.add_attachment("any ruby object", position: string.length)
4154
puts hello_world # => "Hello, World! "
4255
puts hello_world.attachments # => ["any ruby object"]
56+
57+
# delete the attachment character to remove the attachment
4358
hello_world[-1..-1] = ''
4459
puts hello_world.attachments # => []
4560
```
61+
62+
## Detailed Usage
63+
For more detailed usage, see the test suite.
64+
65+
## Used By
66+
- [Instruct](https://github.com/instruct-rb/instruct) - instruct LLMs to do what you want

0 commit comments

Comments
 (0)
0