Class: INat::Report::DataSet
- Inherits:
-
Object
- Object
- INat::Report::DataSet
- Includes:
- Enumerable, INat, INat::Report
- Defined in:
- lib/inat/data/sets/dataset.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
TODO: переделать select так, чтобы не было необходимости во внешнем присваивании.
-
#observations ⇒ Object
readonly
Returns the value of attribute observations.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
Instance Method Summary collapse
- #&(other) ⇒ Object
- #-(other) ⇒ Object
- #<<(observation) ⇒ Object
- #count ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #include?(observation) ⇒ Boolean (also: #===)
-
#initialize(object, observations, time: Time::new) ⇒ DataSet
constructor
A new instance of DataSet.
- #reverse_each ⇒ Object
- #to_a ⇒ Object
- #to_list(lister = Listers::SPECIES, sorter: nil) ⇒ Object
- #where(&block) ⇒ Object
- #|(other) ⇒ Object
Constructor Details
#initialize(object, observations, time: Time::new) ⇒ DataSet
Returns a new instance of DataSet.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/inat/data/sets/dataset.rb', line 15 def initialize object, observations, time: Time::new @object = object @time = time @observations = observations.sort_by { |o| o.sort_key }.uniq @sorted = true @by_id = {} @observations.each do |o| @by_id[o.id] = o end end |
Instance Attribute Details
#object ⇒ Object
TODO: переделать select так, чтобы не было необходимости во внешнем присваивании
12 13 14 |
# File 'lib/inat/data/sets/dataset.rb', line 12 def object @object end |
#observations ⇒ Object (readonly)
Returns the value of attribute observations.
13 14 15 |
# File 'lib/inat/data/sets/dataset.rb', line 13 def observations @observations end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
11 12 13 |
# File 'lib/inat/data/sets/dataset.rb', line 11 def time @time end |
Class Method Details
.zero ⇒ Object
26 27 28 |
# File 'lib/inat/data/sets/dataset.rb', line 26 def self.zero new nil, [] end |
Instance Method Details
#&(other) ⇒ Object
94 95 96 97 |
# File 'lib/inat/data/sets/dataset.rb', line 94 def & other obj = @object == other.object ? @object : nil INat::Report::DataSet::new obj, @observations.select { |o| other.include?(o) }, time: Time::new end |
#-(other) ⇒ Object
99 100 101 102 |
# File 'lib/inat/data/sets/dataset.rb', line 99 def - other obj = @object == other.object ? @object : nil INat::Report::DataSet::new obj, @observations.select { |o| !other.include?(o) }, time: Time::new end |
#<<(observation) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/inat/data/sets/dataset.rb', line 79 def << observation raise TypeError, "Argument must be an Observation (#{ observation.inspect })!" unless Entity::Observation === observation # TODO: добавить массивы и прочее if !self.include?(observation) @observations << observation @by_id[observation.id] = observation @sorted = false end end |
#count ⇒ Object
56 57 58 |
# File 'lib/inat/data/sets/dataset.rb', line 56 def count @observations.size end |
#each ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/inat/data/sets/dataset.rb', line 32 def each if block_given? @observations.sort_by! { |o| o.sort_key } unless @sorted @sorted = true @observations.each do |o| yield o end else to_enum :each end end |
#empty? ⇒ Boolean
68 69 70 |
# File 'lib/inat/data/sets/dataset.rb', line 68 def empty? @observations.empty? end |
#include?(observation) ⇒ Boolean Also known as: ===
64 65 66 |
# File 'lib/inat/data/sets/dataset.rb', line 64 def include? observation @by_id.has_key? observation.id end |
#reverse_each ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/inat/data/sets/dataset.rb', line 44 def reverse_each if block_given? @observations.sort_by! { |o| o.sort_key } unless @sorted @sorted = true @observations.reverse_each do |o| yield o end else to_enum :reverse_each end end |
#to_a ⇒ Object
104 105 106 |
# File 'lib/inat/data/sets/dataset.rb', line 104 def to_a @observations.dup end |
#to_list(lister = Listers::SPECIES, sorter: nil) ⇒ Object
60 61 62 |
# File 'lib/inat/data/sets/dataset.rb', line 60 def to_list lister = Listers::SPECIES, sorter: nil List::new self, lister, sorter: sorter, time: @time end |