Class: Scrawl
- Inherits:
-
Object
- Object
- Scrawl
- Defined in:
- lib/scrawl.rb,
lib/scrawl/version.rb
Constant Summary collapse
- KEY_VALUE_DELIMITER =
"="- PAIR_DELIMITER =
" "- NAMESPACE_DELIMITER =
"."- VERSION =
"2.0.0"
Instance Attribute Summary collapse
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Instance Method Summary collapse
-
#initialize(*trees) ⇒ Scrawl
constructor
A new instance of Scrawl.
- #inspect(namespace = nil) ⇒ Object
- #merge(hash) ⇒ Object
- #to_h ⇒ Object
- #to_hash ⇒ Object
- #to_s(namespace = nil) ⇒ Object
Constructor Details
#initialize(*trees) ⇒ Scrawl
Returns a new instance of Scrawl.
10 11 12 |
# File 'lib/scrawl.rb', line 10 def initialize(*trees) @tree = trees.inject({}) { |global, tree| global.merge(tree) } end |
Instance Attribute Details
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
8 9 10 |
# File 'lib/scrawl.rb', line 8 def tree @tree end |
Instance Method Details
#inspect(namespace = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/scrawl.rb', line 18 def inspect(namespace = nil) @tree.map do |key, value| unless value.respond_to?(:to_hash) label(namespace, key) + KEY_VALUE_DELIMITER + element(value) else Scrawl.new(value).inspect(key) end end.join(PAIR_DELIMITER) end |
#merge(hash) ⇒ Object
14 15 16 |
# File 'lib/scrawl.rb', line 14 def merge(hash) @tree.merge!(hash.to_hash) end |
#to_h ⇒ Object
36 37 38 |
# File 'lib/scrawl.rb', line 36 def to_h tree.to_h end |
#to_hash ⇒ Object
32 33 34 |
# File 'lib/scrawl.rb', line 32 def to_hash tree.to_hash end |
#to_s(namespace = nil) ⇒ Object
28 29 30 |
# File 'lib/scrawl.rb', line 28 def to_s(namespace = nil) inspect(namespace) end |