Class: Twitter::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Memoizable, Utils
Defined in:
lib/twitter/base.rb

Direct Known Subclasses

Configuration, Entity, Geo, Identity, Language, Metadata, OEmbed, Place, ProfileBanner, RateLimit, Relationship, Settings, Size, Streaming::StallWarning, Suggestion, Token, Trend

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Utils

flat_pmap, pmap, pmap_with_index

Constructor Details

- (Twitter::Base) initialize(attrs = {})

Initializes a new object

Parameters:

  • attrs (Hash) (defaults to: {})


112
113
114
# File 'lib/twitter/base.rb', line 112

def initialize(attrs = {})
  @attrs = attrs || {}
end

Instance Attribute Details

- (Object) attrs (readonly) Also known as: to_h

Returns the value of attribute attrs



12
13
14
# File 'lib/twitter/base.rb', line 12

def attrs
  @attrs
end

Class Method Details

+ (Object) attr_reader(*attrs)

Define methods that retrieve the value from attributes

Parameters:

  • attrs (Array, Symbol)


21
22
23
24
25
26
# File 'lib/twitter/base.rb', line 21

def attr_reader(*attrs)
  attrs.each do |attr|
    define_attribute_method(attr)
    define_predicate_method(attr)
  end
end

+ (Object) display_uri_attr_reader

Define display_uri attribute methods



55
56
57
58
59
60
# File 'lib/twitter/base.rb', line 55

def display_uri_attr_reader
  define_attribute_method(:display_url)
  alias_method(:display_uri, :display_url)
  define_predicate_method(:display_uri, :display_url)
  alias_method(:display_url?, :display_uri?)
end

+ (Object) object_attr_reader(klass, key1, key2 = nil)

Define object methods from attributes

Parameters:

  • klass (Symbol)
  • key1 (Symbol)
  • key2 (Symbol) (defaults to: nil)


33
34
35
36
# File 'lib/twitter/base.rb', line 33

def object_attr_reader(klass, key1, key2 = nil)
  define_attribute_method(key1, klass, key2)
  define_predicate_method(key1)
end

+ (Object) uri_attr_reader(*attrs)

Define URI methods from attributes

Parameters:

  • attrs (Array, Symbol)


41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/twitter/base.rb', line 41

def uri_attr_reader(*attrs)
  attrs.each do |uri_key|
    array = uri_key.to_s.split('_')
    index = array.index('uri')
    array[index] = 'url'
    url_key = array.join('_').to_sym
    define_uri_method(uri_key, url_key)
    alias_method(url_key, uri_key)
    define_predicate_method(uri_key, url_key)
    alias_method(:#{url_key}?", :#{uri_key}?")
  end
end

Instance Method Details

- (Object) [](method)

Fetches an attribute of an object using hash notation

Parameters:

  • method (String, Symbol)

    Message to send to the object



119
120
121
122
123
# File 'lib/twitter/base.rb', line 119

def [](method)
  send(method.to_sym)
rescue NoMethodError
  nil
end