Class: Leetcoder::Object
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Leetcoder::Object
- Defined in:
- lib/leetcoder/leetcoder/object.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Object
constructor
A new instance of Object.
- #to_ostruct(obj) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Object
7 8 9 |
# File 'lib/leetcoder/leetcoder/object.rb', line 7 def initialize(attributes) super to_ostruct(attributes) end |
Class Method Details
.from_html(html) ⇒ Object
15 16 17 |
# File 'lib/leetcoder/leetcoder/object.rb', line 15 def self.from_html(html) Nokogiri::HTML(html) end |
.from_response(response, key:) ⇒ Object
11 12 13 |
# File 'lib/leetcoder/leetcoder/object.rb', line 11 def self.from_response(response, key:) new(response.dig(*key)) end |
Instance Method Details
#to_ostruct(obj) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/leetcoder/leetcoder/object.rb', line 19 def to_ostruct(obj) case obj.class when Hash OpenStruct.new(obj.tranform_values { |val| to_ostruct(val) }) when Array obj.map { |o| to_ostruct(o) } else # Assumed to be a primitive value obj end end |