Class: Tweetwine::Tweet

Inherits:
Object
  • Object
show all
Defined in:
lib/tweetwine/tweet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record, paths) ⇒ Tweet

Returns a new instance of Tweet.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tweetwine/tweet.rb', line 7

def initialize(record, paths)
  if field_present? record, paths[:retweet]
    @rt_user = parse_string_field record, paths[:from_user]
    fields   = Support.find_hash_path record, paths[:retweet]
  else
    @rt_user = nil
    fields   = record
  end
  @to_user    = parse_string_field fields, paths[:to_user]
  @from_user  = parse_string_field fields, paths[:from_user]
  raise ArgumentError, 'from user record field is required' unless @from_user
  @created_at = parse_time_field   fields, paths[:created_at]
  @status     = parse_string_field fields, paths[:status]
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



5
6
7
# File 'lib/tweetwine/tweet.rb', line 5

def created_at
  @created_at
end

#from_userObject (readonly)

Returns the value of attribute from_user.



5
6
7
# File 'lib/tweetwine/tweet.rb', line 5

def from_user
  @from_user
end

#rt_userObject (readonly)

Returns the value of attribute rt_user.



5
6
7
# File 'lib/tweetwine/tweet.rb', line 5

def rt_user
  @rt_user
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/tweetwine/tweet.rb', line 5

def status
  @status
end

#to_userObject (readonly)

Returns the value of attribute to_user.



5
6
7
# File 'lib/tweetwine/tweet.rb', line 5

def to_user
  @to_user
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/tweetwine/tweet.rb', line 38

def ==(other)
  other.is_a?(self.class) &&
    self.rt_user    == other.rt_user    &&
    self.to_user    == other.to_user    &&
    self.from_user  == other.from_user  &&
    self.created_at == other.created_at &&
    self.status     == other.status
end

#reply?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/tweetwine/tweet.rb', line 34

def reply?
  !@to_user.nil?
end

#retweet?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/tweetwine/tweet.rb', line 26

def retweet?
  !@rt_user.nil?
end

#status?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/tweetwine/tweet.rb', line 30

def status?
  !@status.nil?
end

#timestamped?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/tweetwine/tweet.rb', line 22

def timestamped?
  !@created_at.nil?
end