Class: Anilistrb::AnilistObj
- Inherits:
-
Object
- Object
- Anilistrb::AnilistObj
- Defined in:
- lib/Anilistrb/AnilistObj.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#initialize(json) ⇒ AnilistObj
constructor
A new instance of AnilistObj.
- #to_s ⇒ Object
- #to_snakecase(str) ⇒ Object
Constructor Details
#initialize(json) ⇒ AnilistObj
Returns a new instance of AnilistObj.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/Anilistrb/AnilistObj.rb', line 5 def initialize(json) @data = json @attributes = [] unless @data.nil? @data.each do |var, val| snaked = to_snakecase(var) self.class.__send__(:attr_accessor, snaked) self.__send__("#{snaked}=", val) @attributes.push(snaked) end end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/Anilistrb/AnilistObj.rb', line 3 def attributes @attributes end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/Anilistrb/AnilistObj.rb', line 3 def data @data end |
Instance Method Details
#to_s ⇒ Object
25 26 27 |
# File 'lib/Anilistrb/AnilistObj.rb', line 25 def to_s data end |
#to_snakecase(str) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/Anilistrb/AnilistObj.rb', line 18 def to_snakecase(str) str.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_').downcase end |