Class: HumansRb

Inherits:
Object
  • Object
show all
Defined in:
lib/humans_rb.rb,
lib/humans_rb/parser.rb,
lib/humans_rb/version.rb,
lib/humans_rb/transform.rb

Defined Under Namespace

Classes: Parser, Transform

Constant Summary collapse

VERSION =
"0.0.6"

Instance Method Summary collapse

Constructor Details

#initialize(url_or_string) ⇒ HumansRb

Returns a new instance of HumansRb.



8
9
10
# File 'lib/humans_rb.rb', line 8

def initialize(url_or_string)
  @url_or_string = url_or_string
end

Instance Method Details

#bodyObject



12
13
14
15
16
17
18
19
# File 'lib/humans_rb.rb', line 12

def body
  if @url_or_string =~ /^http/
    @url_or_string << "/humans.txt" if !(@url_or_string =~ /humans\.txt$/)
    @url_or_string = Typhoeus.get(@url_or_string, accept_encoding: "gzip").body
  end

  normalize_string(@url_or_string)
end

#parseObject



21
22
23
24
25
# File 'lib/humans_rb.rb', line 21

def parse
  Transform.new.apply(Parser.new.parse(body))
rescue Parslet::ParseFailed => failure
  puts failure.cause.ascii_tree
end