Module: JSONData::Collection
- Defined in:
- lib/json_data/collection.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
- #data_source ⇒ Object writeonly
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#data_source=(json) ⇒ Object
25 26 27 28 |
# File 'lib/json_data/collection.rb', line 25 def data_source=(json) @data_source = parser.parse(json) create_data_objects end |
Class Method Details
.included(base) ⇒ Object
15 16 17 18 |
# File 'lib/json_data/collection.rb', line 15 def self.included(base) base.send :include, Enumerable base.send :extend, ClassMethods end |
Instance Method Details
#each(&block) ⇒ Object
30 31 32 |
# File 'lib/json_data/collection.rb', line 30 def each(&block) data_source.each { |d| block.call(d) } end |
#empty? ⇒ Boolean
38 39 40 |
# File 'lib/json_data/collection.rb', line 38 def empty? data_source.empty? end |
#initialize(options = {}) ⇒ Object
20 21 22 23 |
# File 'lib/json_data/collection.rb', line 20 def initialize( = {}) @parser = .fetch(:parser) { Parser.new } self.data_source = .fetch(:data_source) { [] } end |
#valid? ⇒ Boolean
34 35 36 |
# File 'lib/json_data/collection.rb', line 34 def valid? !empty? && all?(&:valid?) end |