Module: AutoPilot

Defined in:
lib/auto_pilot.rb,
lib/auto_pilot/api.rb,
lib/auto_pilot/request.rb,
lib/auto_pilot/util/log.rb,
lib/auto_pilot/configure.rb,
lib/auto_pilot/util/version.rb,
lib/auto_pilot/url_formatter.rb,
lib/auto_pilot/html_converter.rb,
lib/auto_pilot/document_parser.rb,
lib/auto_pilot/template_helper.rb,
lib/auto_pilot/markdown_converter.rb

Defined Under Namespace

Modules: TemplateHelper, URLFormatter Classes: API, Config, DocumentParser, HtmlConverter, Log, MarkdownConverter, Request

Constant Summary collapse

BASE_URL =
'http://stackoverflow.com/questions'
VERSION =
'2.0.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



3
4
5
# File 'lib/auto_pilot/configure.rb', line 3

def configuration
  @configuration
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



6
7
8
9
10
# File 'lib/auto_pilot/configure.rb', line 6

def self.configure
  self.configuration ||= Config.new
  yield configuration
  configuration
end

.get_api_answersObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/auto_pilot.rb', line 13

def get_api_answers
  parsed_documents = []
  answers = AutoPilot::API.new.get_answers
  answers.each do |answer|
    question_id = answer[:question_id]
    answer_id   = answer[:answer_id]
    url = page_with_my_answer(question_id)
    doc = Request.fetch url
    # Log.green "question id #{question_id} | answer id #{answer_id}"
    parsed_documents << DocumentParser.new(doc, question_id, answer_id)
  end
  parsed_documents
end

.page_with_my_answer(id) ⇒ Object



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

def page_with_my_answer(id)
  "#{BASE_URL}/#{id}/"
end

.write_files(parsed_documents) ⇒ Object



31
32
33
34
35
36
# File 'lib/auto_pilot.rb', line 31

def write_files(parsed_documents)
  parsed_documents.each do |doc|
    HtmlConverter.new doc     if AutoPilot.configuration.format.include? :html
    MarkdownConverter.new doc if AutoPilot.configuration.format.include? :md
  end
end