Class: Tributa::Table
- Inherits:
-
Object
- Object
- Tributa::Table
- Defined in:
- lib/tributa/table.rb
Defined Under Namespace
Classes: Row
Instance Attribute Summary collapse
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
- #as_json ⇒ Object
- #find_all_by(canton:, community:, year:) ⇒ Object
-
#initialize(rows) ⇒ Table
constructor
A new instance of Table.
- #to_json ⇒ Object
Constructor Details
#initialize(rows) ⇒ Table
Returns a new instance of Table.
7 8 9 |
# File 'lib/tributa/table.rb', line 7 def initialize(rows) @rows = rows end |
Instance Attribute Details
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
5 6 7 |
# File 'lib/tributa/table.rb', line 5 def rows @rows end |
Instance Method Details
#as_json ⇒ Object
19 20 21 22 23 |
# File 'lib/tributa/table.rb', line 19 def as_json { rows: rows.map(&:as_json) } end |
#find_all_by(canton:, community:, year:) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/tributa/table.rb', line 11 def find_all_by(canton:, community:, year:) rows.find_all do |row| row.canton == canton && row.community == community && row.year == year.to_s end end |
#to_json ⇒ Object
25 26 27 |
# File 'lib/tributa/table.rb', line 25 def to_json as_json.to_json end |