Class: 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 collapse
- 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
-
#<<(attributes) ⇒ Object
(also: #merge!)
Append new attributes to the string.
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
-
#initialize(proxy) ⇒ NSRangedProxyAttributeHash
constructor
A new instance of NSRangedProxyAttributeHash.
- #inspect ⇒ String
-
#to_hash ⇒ NSMutableDictionary
Return a hash of the attributes, but without transforming constant names.
Constructor Details
#initialize(proxy) ⇒ NSRangedProxyAttributeHash
Returns a new instance of NSRangedProxyAttributeHash.
39 40 41 |
# File 'lib/hotcocoa/attributed_string_helpers.rb', line 39 def initialize proxy @proxy = proxy end |
Instance Method Details
#<<(attributes) ⇒ Object Also known as: merge!
Append new attributes to the string
61 62 63 64 |
# File 'lib/hotcocoa/attributed_string_helpers.rb', line 61 def << attributes attributes.each_pair { |k, v| self[k] = v } self end |
#[](k) ⇒ Object
43 44 45 46 |
# File 'lib/hotcocoa/attributed_string_helpers.rb', line 43 def [] k k = attribute_for_key k @proxy.string.attribute k, atIndex: @proxy.range.first, effectiveRange: nil end |
#[]=(k, v) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/hotcocoa/attributed_string_helpers.rb', line 48 def []= k, v k = attribute_for_key k @proxy.string.removeAttribute k, range: @proxy.range.to_NSRange(@proxy.string.length) @proxy.string.addAttribute k, value: v, range: @proxy.range.to_NSRange(@proxy.string.length) end |
#inspect ⇒ String
79 80 81 |
# File 'lib/hotcocoa/attributed_string_helpers.rb', line 79 def inspect to_hash.inspect end |
#to_hash ⇒ NSMutableDictionary
Return a hash of the attributes, but without transforming constant names.
72 73 74 75 76 |
# File 'lib/hotcocoa/attributed_string_helpers.rb', line 72 def to_hash dict = @proxy.string.attributesAtIndex @proxy.range.first, effectiveRange: nil NSMutableDictionary.dictionaryWithDictionary dict end |