Class: Tweetkit::Response::Tweets::Fields
- Inherits:
-
Object
- Object
- Tweetkit::Response::Tweets::Fields
- Defined in:
- lib/tweetkit/response.rb
Defined Under Namespace
Classes: Field
Instance Attribute Summary collapse
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#media_fields ⇒ Object
Returns the value of attribute media_fields.
-
#place_fields ⇒ Object
Returns the value of attribute place_fields.
-
#poll_fields ⇒ Object
Returns the value of attribute poll_fields.
-
#tweet_fields ⇒ Object
Returns the value of attribute tweet_fields.
-
#user_fields ⇒ Object
Returns the value of attribute user_fields.
Instance Method Summary collapse
- #build_and_normalize_field(field, field_type) ⇒ Object
- #build_and_normalize_fields(fields) ⇒ Object
-
#initialize(fields) ⇒ Fields
constructor
A new instance of Fields.
- #method_missing(method, **args) ⇒ Object
- #respond_to_missing?(method, *args) ⇒ Boolean
Constructor Details
#initialize(fields) ⇒ Fields
Returns a new instance of Fields.
550 551 552 553 |
# File 'lib/tweetkit/response.rb', line 550 def initialize(fields) @fields = fields build_and_normalize_fields(fields) unless fields.nil? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, **args) ⇒ Object
567 568 569 570 571 |
# File 'lib/tweetkit/response.rb', line 567 def method_missing(method, **args) return nil if VALID_FIELDS.include?(method.to_s) super end |
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
548 549 550 |
# File 'lib/tweetkit/response.rb', line 548 def fields @fields end |
#media_fields ⇒ Object
Returns the value of attribute media_fields.
548 549 550 |
# File 'lib/tweetkit/response.rb', line 548 def media_fields @media_fields end |
#place_fields ⇒ Object
Returns the value of attribute place_fields.
548 549 550 |
# File 'lib/tweetkit/response.rb', line 548 def place_fields @place_fields end |
#poll_fields ⇒ Object
Returns the value of attribute poll_fields.
548 549 550 |
# File 'lib/tweetkit/response.rb', line 548 def poll_fields @poll_fields end |
#tweet_fields ⇒ Object
Returns the value of attribute tweet_fields.
548 549 550 |
# File 'lib/tweetkit/response.rb', line 548 def tweet_fields @tweet_fields end |
#user_fields ⇒ Object
Returns the value of attribute user_fields.
548 549 550 |
# File 'lib/tweetkit/response.rb', line 548 def user_fields @user_fields end |
Instance Method Details
#build_and_normalize_field(field, field_type) ⇒ Object
563 564 565 |
# File 'lib/tweetkit/response.rb', line 563 def build_and_normalize_field(field, field_type) Field.new(field, field_type) end |
#build_and_normalize_fields(fields) ⇒ Object
555 556 557 558 559 560 561 |
# File 'lib/tweetkit/response.rb', line 555 def build_and_normalize_fields(fields) fields.each_key do |field_type| normalized_field = build_and_normalize_field(@fields[field_type], field_type) instance_variable_set(:"@#{field_type}", normalized_field) self.class.define_method(field_type) { instance_variable_get("@#{field_type}") } end end |
#respond_to_missing?(method, *args) ⇒ Boolean
573 574 575 |
# File 'lib/tweetkit/response.rb', line 573 def respond_to_missing?(method, *args) VALID_FIELDS.include?(method.to_s) || super end |