Class: MetricTools::IndexTree
- Inherits:
-
Object
- Object
- MetricTools::IndexTree
- Defined in:
- lib/metric_tools/index_tree.rb
Overview
Tree構造のHash
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #[]=(*args) ⇒ Object
- #clear ⇒ Object
-
#initialize(hash_or_json = nil) ⇒ IndexTree
constructor
A new instance of IndexTree.
- #to_json(option = {}) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(hash_or_json = nil) ⇒ IndexTree
Returns a new instance of IndexTree.
10 11 12 13 14 15 16 17 18 |
# File 'lib/metric_tools/index_tree.rb', line 10 def initialize(hash_or_json=nil) if hash_or_json.kind_of? Hash build_with_hash(hash_or_json) elsif hash_or_json.kind_of? String build_with_json(hash_or_json) else @_hash = {} end end |
Instance Method Details
#[](*args) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/metric_tools/index_tree.rb', line 21 def [](*args) ret = nil process_tracing_keys(@_hash, args) {|obj, key, is_leaf| ret = obj[key] if is_leaf } ret end |
#[]=(*args) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/metric_tools/index_tree.rb', line 29 def []=(*args) val = args.pop process_tracing_keys(@_hash, args) {|obj, key, is_leaf| if is_leaf obj[key] = val else obj[key] ||= {} end } end |
#clear ⇒ Object
40 41 42 |
# File 'lib/metric_tools/index_tree.rb', line 40 def clear @_hash = {} end |
#to_json(option = {}) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/metric_tools/index_tree.rb', line 48 def to_json(option={}) if option[:pretty] JSON.pretty_generate(@_hash) else JSON.generate(@_hash) end end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/metric_tools/index_tree.rb', line 44 def to_s @_hash.to_s end |