Class: Itest5ch::Comment

Inherits:
Object
  • Object
show all
Defined in:
lib/itest5ch/comment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number:, name:, mail:, date:, id:, message:, thread:) ⇒ Comment

Returns a new instance of Comment.

Parameters:

  • number (Integer)
  • name (String)
  • mail (String)
  • date (Time)
  • id (String)
  • message (String)
  • thread (Itest5ch::Thread)


40
41
42
43
44
45
46
47
48
# File 'lib/itest5ch/comment.rb', line 40

def initialize(number:, name:, mail:, date:, id:, message:, thread:) # rubocop:disable Metrics/ParameterLists
  @number  = number
  @name    = name
  @mail    = mail
  @date    = date
  @id      = id
  @message = message
  @thread  = thread
end

Instance Attribute Details

#dateTime

Returns:

  • (Time)


19
20
21
# File 'lib/itest5ch/comment.rb', line 19

def date
  @date
end

#idString

Returns:

  • (String)


23
24
25
# File 'lib/itest5ch/comment.rb', line 23

def id
  @id
end

#mailString

Returns:

  • (String)


15
16
17
# File 'lib/itest5ch/comment.rb', line 15

def mail
  @mail
end

#messageString

Returns:

  • (String)


27
28
29
# File 'lib/itest5ch/comment.rb', line 27

def message
  @message
end

#nameString

Returns:

  • (String)


11
12
13
# File 'lib/itest5ch/comment.rb', line 11

def name
  @name
end

#numberInteger

Returns:

  • (Integer)


7
8
9
# File 'lib/itest5ch/comment.rb', line 7

def number
  @number
end

#threadItest5ch::Thread

Returns:



31
32
33
# File 'lib/itest5ch/comment.rb', line 31

def thread
  @thread
end

Instance Method Details

#anchor_numbersArray<Integer> Also known as: reply_numbers

Returns:

  • (Array<Integer>)


51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/itest5ch/comment.rb', line 51

def anchor_numbers
  numbers =
    message.scan(/[>>]+([0-90-9\-]+)/).map do |result|
      str = result.first.tr("0-9", "0-9")
      if (m = str.match(/([0-9]+)-([0-9]+)/))
        (m[1].to_i..m[2].to_i).to_a
      else
        str.to_i
      end
    end

  numbers.flatten.compact
end

#id_checker_urlString?

Get Id checker url for http://hissi.org

Returns:

  • (String)
  • (nil)

    #id is empty

See Also:



83
84
85
86
87
88
89
# File 'lib/itest5ch/comment.rb', line 83

def id_checker_url
  return nil if !id || id.empty?

  ymd = date.strftime("%Y%m%d")
  encoded_id = Base64.strict_encode64(id).delete("=")
  "http://hissi.org/read.php/#{thread.board}/#{ymd}/#{encoded_id}.html"
end

#pc_urlString

Returns:

  • (String)


68
69
70
# File 'lib/itest5ch/comment.rb', line 68

def pc_url
  "#{thread.pc_url}/#{number}"
end

#smartphone_urlString

Returns:

  • (String)


73
74
75
# File 'lib/itest5ch/comment.rb', line 73

def smartphone_url
  "#{thread.smartphone_url}/#{number}"
end