Class: CrowdFundingParser::Parser::An9

Inherits:
General
  • Object
show all
Defined in:
lib/crowd_funding_parser/parser/an9.rb

Instance Method Summary collapse

Methods inherited from General

#get_doc_through_url, #get_id, #get_json_through_url, #get_project, #get_result, #parse_content_data, #parse_tracking_data

Constructor Details

#initializeAn9

Returns a new instance of An9.



8
9
10
11
# File 'lib/crowd_funding_parser/parser/an9.rb', line 8

def initialize
  @url = "http://www.an9.com.tw/Dream/"
  @status_css_class = ".sideCon>a"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CrowdFundingParser::Parser::General

Instance Method Details

#get_main_categories(add_categories) ⇒ Object



13
14
15
# File 'lib/crowd_funding_parser/parser/an9.rb', line 13

def get_main_categories(add_categories)
  add_categories.select { |c| c[:parent_id].nil? }
end


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/crowd_funding_parser/parser/an9.rb', line 17

def get_project_links(required_status = "online")
  links = []
  error_count = 0
  not_found_count = 0
  Parallel.each(1..100000, in_precesses: 2, in_threads: 5, progress: "Get #{self} links") do |i|
    begin
      link = @url + i.to_s
      project = get_doc_through_url(link)
      not_found_message = project.css(".actMsg p")
      if not_found_message.present? && get_string(not_found_message).match(/不存在/)
        not_found_count += 1
      else
        status = get_status(get_string(project.css(@status_css_class)))

        if status == required_status
          links << link
        end
        not_found_count = 0
        error_count = 0
      end
    rescue Exception => e
      error_count += 1
      raise Parallel::Break if not_found_count >= 50 || error_count >= 50
    end
  end

  links
end