Class: Calil::Library
- Inherits:
-
Object
show all
- Defined in:
- lib/calil/library.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(element) ⇒ Library
Returns a new instance of Library.
21
22
23
|
# File 'lib/calil/library.rb', line 21
def initialize(element)
@element = element
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(action, *args) ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/calil/library.rb', line 32
def method_missing(action, *args)
if %w(systemid systemname libkey libid short formal url_pc address pref city post tel geocode category image).include? action.to_s
@element.elements[action.to_s].text
else
super
end
end
|
Class Method Details
.find(params = {}) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/calil/library.rb', line 5
def self.find(params = {})
params.merge!(appkey: ENV["CALIL_APP_KEY"]) unless params[:appkey]
raise "calil appkey notfound" unless params[:appkey]
query = params.map {|k,v| "#{k}=#{CGI.escape(v.to_s)}" }.join("&").to_s
url = "http://api.calil.jp/library?#{query}"
libraries = []
REXML::Document.new(open(url)).elements.each('Libraries/Library') do |element|
libraries << Library.new(element)
end
libraries
end
|
Instance Method Details
#inspect ⇒ Object
25
26
27
28
29
30
|
# File 'lib/calil/library.rb', line 25
def inspect
attr_body = %w(systemid systemname libkey libid short formal url_pc address pref city post tel geocode category image).map do |method_name|
eval("\"#{method_name}: '#{send(method_name)}'\"")
end.join(", ")
"#<Library #{attr_body}>"
end
|