Class: Motion::Element
- Inherits:
-
Object
- Object
- Motion::Element
- Defined in:
- lib/motion/element.rb
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #attributes ⇒ Object
- #checked? ⇒ Boolean
- #data ⇒ Object
- #form_data ⇒ Object
- #id ⇒ Object
-
#initialize(raw) ⇒ Element
constructor
A new instance of Element.
- #tag_name ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(raw) ⇒ Element
Returns a new instance of Element.
13 14 15 |
# File 'lib/motion/element.rb', line 13 def initialize(raw) @raw = raw.freeze end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
11 12 13 |
# File 'lib/motion/element.rb', line 11 def raw @raw end |
Class Method Details
.from_raw(raw) ⇒ Object
7 8 9 |
# File 'lib/motion/element.rb', line 7 def self.from_raw(raw) new(raw) if raw end |
Instance Method Details
#[](key) ⇒ Object
33 34 35 36 37 |
# File 'lib/motion/element.rb', line 33 def [](key) key = key.to_s attributes[key] || attributes[key.tr("_", "-")] end |
#attributes ⇒ Object
29 30 31 |
# File 'lib/motion/element.rb', line 29 def attributes raw.fetch("attributes", {}) end |
#checked? ⇒ Boolean
25 26 27 |
# File 'lib/motion/element.rb', line 25 def checked? raw["checked"] end |
#data ⇒ Object
57 58 59 60 61 |
# File 'lib/motion/element.rb', line 57 def data return @data if defined?(@data) @data = DataAttributes.new(self) end |
#form_data ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/motion/element.rb', line 63 def form_data return @form_data if defined?(@form_data) @form_data = ActionController::Parameters.new( Rack::Utils.parse_nested_query( raw.fetch("formData", "") ) ) end |
#id ⇒ Object
39 40 41 |
# File 'lib/motion/element.rb', line 39 def id self[:id] end |
#tag_name ⇒ Object
17 18 19 |
# File 'lib/motion/element.rb', line 17 def tag_name raw["tagName"] end |
#value ⇒ Object
21 22 23 |
# File 'lib/motion/element.rb', line 21 def value raw["value"] end |