Class: PeriodicTable::ApiResponse
- Inherits:
-
Object
- Object
- PeriodicTable::ApiResponse
- Defined in:
- lib/periodic_table/periodic_table_api.rb
Instance Method Summary collapse
-
#initialize(result) ⇒ ApiResponse
constructor
A new instance of ApiResponse.
- #method_missing(method) ⇒ Object
Constructor Details
#initialize(result) ⇒ ApiResponse
Returns a new instance of ApiResponse.
19 20 21 22 |
# File 'lib/periodic_table/periodic_table_api.rb', line 19 def initialize(result) xml = Nokogiri::XML.parse(result) @data = xml.xpath("NewDataSet/Table").first.element_children end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/periodic_table/periodic_table_api.rb', line 24 def method_missing(method) method = method.to_s # the webservicex api mispells "electronegativity" method = 'eletronegativity' if method == 'electronegativity' element = @data.find { |e| e.name =~ /#{method.gsub('_', '')}/i } element.text if element end |