Class: Twroute::TweetRoute
- Inherits:
-
Object
- Object
- Twroute::TweetRoute
- Defined in:
- lib/twroute/tweet_route.rb
Instance Attribute Summary collapse
-
#tweet_parser ⇒ Object
Returns the value of attribute tweet_parser.
-
#url_pattern ⇒ Object
Returns the value of attribute url_pattern.
Instance Method Summary collapse
- #fill_in_url_pattern ⇒ Object
- #get_post_args ⇒ Object
-
#initialize(tweet_parser, url_pattern) ⇒ TweetRoute
constructor
A new instance of TweetRoute.
- #is_match? ⇒ Boolean
- #parse_tweet(tweet_text) ⇒ Object
- #path ⇒ Object
- #reset ⇒ Object
- #tweet(tweet_hash) ⇒ Object
Constructor Details
#initialize(tweet_parser, url_pattern) ⇒ TweetRoute
Returns a new instance of TweetRoute.
4 5 6 7 |
# File 'lib/twroute/tweet_route.rb', line 4 def initialize(tweet_parser, url_pattern) self.tweet_parser = tweet_parser self.url_pattern = url_pattern end |
Instance Attribute Details
#tweet_parser ⇒ Object
Returns the value of attribute tweet_parser.
3 4 5 |
# File 'lib/twroute/tweet_route.rb', line 3 def tweet_parser @tweet_parser end |
#url_pattern ⇒ Object
Returns the value of attribute url_pattern.
3 4 5 |
# File 'lib/twroute/tweet_route.rb', line 3 def url_pattern @url_pattern end |
Instance Method Details
#fill_in_url_pattern ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/twroute/tweet_route.rb', line 34 def fill_in_url_pattern pattern = self.url_pattern @parsed_hash.keys.each do |key| pattern.gsub!(':' + key.to_s, @parsed_hash[key]) end tweet_h = @tweet_hash.merge({ }) # tweet_h.delete(:user) tweet_h.keys.each do |key| pattern.gsub!(':tweet[' + key.to_s + ']', @tweet_hash[key].to_s) if key != :user end pattern end |
#get_post_args ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/twroute/tweet_route.rb', line 49 def get_post_args post_hash = { } @parsed_hash.keys.each do |key| post_hash["parsed[#{key.to_s}]"] = @parsed_hash[key] end @sender_hash.keys.each do |key| post_hash["sender[#{key.to_s}]"] = @sender_hash[key] end @tweet_hash.keys.each do |key| post_hash["tweet[#{key.to_s}]"] = @tweet_hash[key] if key != :user end post_hash end |
#is_match? ⇒ Boolean
26 27 28 |
# File 'lib/twroute/tweet_route.rb', line 26 def is_match? tweet_parser.is_match? end |
#parse_tweet(tweet_text) ⇒ Object
22 23 24 |
# File 'lib/twroute/tweet_route.rb', line 22 def parse_tweet(tweet_text) @parsed_hash = tweet_parser.parse_tweet(tweet_text) || { } end |
#path ⇒ Object
30 31 32 |
# File 'lib/twroute/tweet_route.rb', line 30 def path fill_in_url_pattern end |
#reset ⇒ Object
16 17 18 19 20 |
# File 'lib/twroute/tweet_route.rb', line 16 def reset @tweet_hash = { } @sender_hash = { } @parsed_hash = { } end |
#tweet(tweet_hash) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/twroute/tweet_route.rb', line 9 def tweet(tweet_hash) reset @tweet_hash = tweet_hash || { } @sender_hash = tweet_hash[:user] || { } parse_tweet(tweet_hash[:text]) end |