Class: Scrawl
- Inherits:
-
Object
- Object
- Scrawl
- Extended by:
- Forwardable
- Defined in:
- lib/scrawl.rb,
lib/scrawl/version.rb
Overview
This is where we define the version number for the gem
Constant Summary collapse
- KEY_VALUE_DELIMITER =
"="- PAIR_DELIMITER =
" "- NAMESPACE_DELIMITER =
"."- VERSION =
"1.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
Constructor Details
#initialize(*trees) ⇒ Scrawl
Returns a new instance of Scrawl.
15 16 17 |
# File 'lib/scrawl.rb', line 15 def initialize(*trees) @tree = trees.inject({}) { |global, tree| global.merge(tree) } end |
Instance Attribute Details
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
11 12 13 |
# File 'lib/scrawl.rb', line 11 def tree @tree end |
Instance Method Details
#inspect(namespace = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/scrawl.rb', line 23 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
19 20 21 |
# File 'lib/scrawl.rb', line 19 def merge(hash) @tree.merge!(hash.to_hash) end |