No commit activity in last 3 years
No release in over 3 years
A String class, but with attributes marking data at specific ranges.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 0
~> 3.0
 Project Readme

attributed_string

Similar to a NSAttributedString in Objective-C, this provides an AttributedString class. It's similar to a normal String, but tracks an array of AttributedString::Attribute instances, each of which references a range and a blob of data about that range.

This is useful for storing string formatting information separately from the plain text, while still being about to do transforms like prepend and append operations.

Example

string    = "This is a test"
range     = Range.new(0, 3)
data      = { weight: :bold }
# This marks the first word as being bold. The implementation of the data is up to you, but here we use a simple Hash.
attribute = AttributedString::Attribute.new(range, data)

attributed_string = AttributedString.new(string, [attribute])

# This prepends another AttributedString, but keeps track of the position of the original attributes.
attributed_string.prepend(another_attributed_string)

# Coalesces overlapping attributes of identical data
attributed_string.fix