Class: Gias::School
- Inherits:
-
Object
show all
- Defined in:
- lib/gias/school.rb
Constant Summary
collapse
- HOST =
"https://ea-edubase-api-prod.azurewebsites.net"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes = {}) ⇒ School
Returns a new instance of School.
11
12
13
|
# File 'lib/gias/school.rb', line 11
def initialize(attributes = {})
@attributes = attributes
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/gias/school.rb', line 19
def method_missing(method_name, *args, &block)
if attribute_names.include?(method_name.to_s)
@attributes[method_name.to_s]
else
super
end
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
9
10
11
|
# File 'lib/gias/school.rb', line 9
def attributes
@attributes
end
|
Class Method Details
.all ⇒ Object
38
39
40
41
42
|
# File 'lib/gias/school.rb', line 38
def all
@all ||= csv.map do |row|
new(row.to_h.transform_keys { (_1) })
end
end
|
.attribute_names ⇒ Object
56
57
58
|
# File 'lib/gias/school.rb', line 56
def attribute_names
||= csv..map { (_1) }
end
|
60
61
62
|
# File 'lib/gias/school.rb', line 60
def ()
.gsub("(", "").gsub(")", "").gsub(" ", "_").underscore
end
|
.csv ⇒ Object
44
45
46
|
# File 'lib/gias/school.rb', line 44
def csv
@csv ||= CSV.parse(csv_data, headers: true, empty_value: nil)
end
|
.csv_data ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/gias/school.rb', line 48
def csv_data
hash = Hash.new do |h, k|
h[k] = URI.open(HOST + "/edubase/downloads/public/edubasealldata#{k}.csv")
end
hash[Date.current.strftime("%Y%m%d")]
end
|
Instance Method Details
#attribute_names ⇒ Object
31
32
33
|
# File 'lib/gias/school.rb', line 31
def attribute_names
self.class.attribute_names
end
|
#inspect ⇒ Object
15
16
17
|
# File 'lib/gias/school.rb', line 15
def inspect
"#<#{self.class.name} #{attributes.map { |k, v| "#{k}: #{v.inspect}"}.join(", ")}>"
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
27
28
29
|
# File 'lib/gias/school.rb', line 27
def respond_to_missing?(method_name, include_private = false)
attribute_names.include?(method_name.to_s) || super
end
|