Class: HotCocoa::NSRangedProxyAttributeHash
- Inherits:
-
Object
- Object
- HotCocoa::NSRangedProxyAttributeHash
- Defined in:
- lib/hotcocoa/attributed_string_helpers.rb
Overview
Similar to a Ruby Hash, except specialized for dealing with a hash of attributes for NSAttributedString objects.
Constant Summary
- ATTRIBUTE_KEYS =
{ font: NSFontAttributeName, paragraph_style: NSParagraphStyleAttributeName, color: NSForegroundColorAttributeName, colour: NSForegroundColorAttributeName, underline_style: NSUnderlineStyleAttributeName, superscript: NSSuperscriptAttributeName, background_color: NSBackgroundColorAttributeName, background_colour: NSBackgroundColorAttributeName, attachment: NSAttachmentAttributeName, ligature: NSLigatureAttributeName, baseline_offset: NSBaselineOffsetAttributeName, kerning: NSKernAttributeName, link: NSLinkAttributeName, stroke_width: NSStrokeWidthAttributeName, stroke_color: NSStrokeColorAttributeName, underline_color: NSUnderlineColorAttributeName, strikethrough_style: NSStrikethroughStyleAttributeName, strikethrough_color: NSStrikethroughColorAttributeName, strikethrough_colour: NSStrikethroughColorAttributeName, shadow: NSShadowAttributeName, obliqueness: NSObliquenessAttributeName, expansion_factor: NSExpansionAttributeName, cursor: NSCursorAttributeName, tool_tip: NSToolTipAttributeName, character_shape: NSCharacterShapeAttributeName, glyph_info: NSGlyphInfoAttributeName, marked_clause_segment: NSMarkedClauseSegmentAttributeName, spelling_state: NSSpellingStateAttributeName }
Instance Method Summary (collapse)
-
- (Object) <<(attributes)
(also: #merge!)
Append new attributes to the string.
- - (Object) [](k)
- - (Object) []=(k, v)
-
- (NSRangedProxyAttributeHash) initialize(proxy)
constructor
A new instance of NSRangedProxyAttributeHash.
- - (String) inspect
-
- (NSMutableDictionary) to_hash
Return a hash of the attributes, but without transforming constant names.
Constructor Details
- (NSRangedProxyAttributeHash) initialize(proxy)
A new instance of NSRangedProxyAttributeHash
43 44 45 |
# File 'lib/hotcocoa/attributed_string_helpers.rb', line 43 def initialize proxy @proxy = proxy end |
Instance Method Details
- (Object) <<(attributes) Also known as: merge!
Append new attributes to the string
65 66 67 68 |
# File 'lib/hotcocoa/attributed_string_helpers.rb', line 65 def << attributes attributes.each_pair { |k, v| self[k] = v } self end |
- (Object) [](k)
47 48 49 50 |
# File 'lib/hotcocoa/attributed_string_helpers.rb', line 47 def [] k k = attribute_for_key k @proxy.string.attribute k, atIndex: @proxy.range.first, effectiveRange: nil end |
- (Object) []=(k, v)
52 53 54 55 56 57 58 59 |
# File 'lib/hotcocoa/attributed_string_helpers.rb', line 52 def []= k, v k = attribute_for_key k @proxy.string.removeAttribute k, range: @proxy.range.relative_to(@proxy.string.length) @proxy.string.addAttribute k, value: v, range: @proxy.range.relative_to(@proxy.string.length) end |
- (String) inspect
83 84 85 |
# File 'lib/hotcocoa/attributed_string_helpers.rb', line 83 def inspect to_hash.inspect end |
- (NSMutableDictionary) to_hash
Return a hash of the attributes, but without transforming constant names.
76 77 78 79 80 |
# File 'lib/hotcocoa/attributed_string_helpers.rb', line 76 def to_hash dict = @proxy.string.attributesAtIndex @proxy.range.first, effectiveRange: nil NSMutableDictionary.dictionaryWithDictionary dict end |