Class: Leafcutter
- Inherits:
-
Object
- Object
- Leafcutter
- Defined in:
- lib/leafcutter.rb
Instance Method Summary collapse
-
#initialize(json) ⇒ Leafcutter
constructor
A new instance of Leafcutter.
- #run(params) ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(json) ⇒ Leafcutter
Returns a new instance of Leafcutter.
2 3 4 |
# File 'lib/leafcutter.rb', line 2 def initialize(json) @data = json end |
Instance Method Details
#run(params) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/leafcutter.rb', line 15 def run(params) keys = @data.keys raise 'There should only be one top level key' if keys.length > 1 raise 'Could not find top level key' if keys.length < 1 key = keys[0] explore_branch @data, key, params end |
#validate ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/leafcutter.rb', line 6 def validate status = { valid: true, errors: [] } # This is like run except we don't know which routes we want # Instead we want to explore all branches and report all the errors we find return validate_branch @data, :condition, status end |