Class: Rtlog::Tweet

Inherits:
Object
  • Object
show all
Includes:
ERB::Util, DirUtils
Defined in:
lib/rtlog/archives.rb

Constant Summary collapse

URL_REGEXP =
/https?(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/
REPRY_REGEXP =
/@(\w+)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DirUtils

#entries

Constructor Details

#initialize(config, path_or_data) ⇒ Tweet

Returns a new instance of Tweet.



76
77
78
79
80
81
82
83
84
85
# File 'lib/rtlog/archives.rb', line 76

def initialize config, path_or_data
  @config = config
  if path_or_data.is_a?(String)
    open(path_or_data) do |io|
      @data = ActiveSupport::JSON.decode(io.read)
    end
  else
    @data = path_or_data
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



87
88
89
90
# File 'lib/rtlog/archives.rb', line 87

def method_missing sym, *args, &block
  return super unless @data.key?(sym.to_s)
  return @data[sym.to_s]
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



74
75
76
# File 'lib/rtlog/archives.rb', line 74

def config
  @config
end

#dataObject (readonly)

Returns the value of attribute data.



73
74
75
# File 'lib/rtlog/archives.rb', line 73

def data
  @data
end

Instance Method Details

#created_atObject



116
117
118
# File 'lib/rtlog/archives.rb', line 116

def created_at
  Time.zone.parse(@data['created_at'])
end

#formatted_textObject



95
96
97
98
99
100
# File 'lib/rtlog/archives.rb', line 95

def formatted_text
  t = h(text)
  t = t.gsub(URL_REGEXP)    { "<a href='#{$&}'>#{$&}</a>" }
  t = t.gsub(REPRY_REGEXP)  { "<a href='http://twitter.com/#{$1}'>@#{$1}</a>" }
  t
end

#idObject



102
103
104
# File 'lib/rtlog/archives.rb', line 102

def id
  @data['id']
end

#mediasObject



106
107
108
109
110
111
112
113
114
# File 'lib/rtlog/archives.rb', line 106

def medias
  unless defined?(@medias) && @medias
    @medias = []
    text.gsub(TwitPic::TWIT_REGEXP) do |m|
      @medias << TwitPic.new(config, m)
    end
  end
  @medias
end