Class: Tributa::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/tributa/table.rb

Defined Under Namespace

Classes: Row

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#rowsObject (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_jsonObject



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_jsonObject



25
26
27
# File 'lib/tributa/table.rb', line 25

def to_json
  as_json.to_json
end