Class: NogizakaBlog::Amazing

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/nogizaka_blog/amazing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yearmonth) ⇒ Amazing

Returns a new instance of Amazing.



13
14
15
16
# File 'lib/nogizaka_blog/amazing.rb', line 13

def initialize(yearmonth)
  @yearmonth = yearmonth
  @member_size = MEMBER.size
end

Instance Attribute Details

#member_sizeObject (readonly)

Returns the value of attribute member_size.



10
11
12
# File 'lib/nogizaka_blog/amazing.rb', line 10

def member_size
  @member_size
end

#yearmonthObject

Returns the value of attribute yearmonth.



11
12
13
# File 'lib/nogizaka_blog/amazing.rb', line 11

def yearmonth
  @yearmonth
end

Instance Method Details

#eachObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/nogizaka_blog/amazing.rb', line 23

def each
  MEMBER.keys.each do |name|
    max = max_page(name)
    @comment = []

    # @comment = 0 when redirected
    if max == -1
      @comment << 0
    elsif max == 0
      url = "http://blog.nogizaka46.com/#{name}/?d=#{@yearmonth}"
      comment_size(url)
    else
      (1..max).each do |n|
        url = "http://blog.nogizaka46.com/#{name}/?p=#{n}&d=#{@yearmonth}"
        comment_size(url)
      end
    end

    if max == -1
      article = 0
    else
      article = @comment.length
    end

    yield name, @comment.sum, article
  end
end

#scraping(&block) ⇒ Object



18
19
20
21
# File 'lib/nogizaka_blog/amazing.rb', line 18

def scraping(&block)
  warn "\e[31m[DEPRECATION] `scraping` is deprecated.  Please use `each` instead.\e[0m"
  each(&block)
end