humans_rb 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dde684101ac3814b2193f370849a1be9b2d34ed5
4
- data.tar.gz: 8b4b31b761892b9527862976d412da7e72d0ca02
3
+ metadata.gz: 97634240b35ca026889376e2e6949e289dd35451
4
+ data.tar.gz: 30ffa9fe37ad1b87715bdb2e6bcb72a533e037ee
5
5
  SHA512:
6
- metadata.gz: ac07ba55eccce60be6391ddcf4fb47f18d2ef5beff6edb013c72c93a1c189c61c254e77c67fe441706ebcef912cd2767341f44386eb1e3127d3bdfb71133d44a
7
- data.tar.gz: 511be9d5b84d8d8eb9deed488af9d1e7b9d307e2eeebfe30b8d607fba18e2da6652258e4b1d93b786fc99bb574588246f875c817472ae0b4bb6d51453fd3443d
6
+ metadata.gz: 19b1bc3ae7f4542fbda8424c73563485d9b8c1fa8009c95a9add47ccad0e47536829217fc639e3223d3364c5b44d654cb95a7dd86db17ab7b1a79998f446b27d
7
+ data.tar.gz: 6d7f0cbe3b33a8446951f22e6a968a77b1701dbcf1f9f8ec1b6c30d291a90814e33a71ea345126e6c91b8896155ac7f13da21ba2b8bb235e80baf11b7cc85733
@@ -18,7 +18,7 @@ class HumansRb
18
18
  rule(:colon) { str(":") }
19
19
  rule(:key) { slash_star.absent? >> newline.absent? >> match("[^:\n]").repeat.as(:key) >> colon }
20
20
  rule(:value) { newline.absent? >> match("[^\n]").repeat.as(:value) }
21
- rule(:key_value_pair) { whitespace? >> key >> space >> value >> newline }
21
+ rule(:key_value_pair) { whitespace? >> key >> space? >> value >> newline }
22
22
  rule(:key_value_pairs) { key_value_pair.repeat(1).as(:values) }
23
23
 
24
24
  rule(:name) { slash_star.absent? >> match("[^\t\n:]").repeat(1).as(:name) >> newline }
@@ -1,3 +1,3 @@
1
1
  class HumansRb
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/humans_rb.rb CHANGED
@@ -10,13 +10,12 @@ class HumansRb
10
10
  end
11
11
 
12
12
  def body
13
- @body ||= if @url_or_string =~ /^http/
13
+ if @url_or_string =~ /^http/
14
14
  @url_or_string << "/humans.txt" if !(@url_or_string =~ /humans\.txt$/)
15
- @url_or_string = Typhoeus.get(@url_or_string, accept_encoding: "gzip").body.
16
- encode('UTF-8', {:invalid => :replace, :undef => :replace, :replace => '?'})
17
- else
18
- @url_or_string.encode('UTF-8', {:invalid => :replace, :undef => :replace, :replace => '?'})
15
+ @url_or_string = Typhoeus.get(@url_or_string, accept_encoding: "gzip").body
19
16
  end
17
+
18
+ normalize_string(@url_or_string)
20
19
  end
21
20
 
22
21
  def parse
@@ -24,4 +23,13 @@ class HumansRb
24
23
  rescue Parslet::ParseFailed => failure
25
24
  puts failure.cause.ascii_tree
26
25
  end
26
+
27
+ private
28
+
29
+ def normalize_string(string)
30
+ string = string.force_encoding("UTF-8")
31
+ string = string.encode("UTF-8", :invalid => :replace, :replace => "")
32
+ string = string.gsub(/^\uFEFF/, "")
33
+ string << "\n"
34
+ end
27
35
  end
data/script/console CHANGED
@@ -1,3 +1,3 @@
1
1
  #! /bin/sh
2
2
 
3
- bundle exec pry -r ./lib/humans.rb
3
+ bundle exec pry -r ./lib/humans_rb.rb
@@ -0,0 +1,73 @@
1
+ /* TEAM */
2
+ Chef:Juanjo Bernabeu
3
+ Contact: hello [at] humanstxt.org
4
+ Twitter: @juanjobernabeu
5
+ From:Barcelona, Catalonia, Spain
6
+
7
+ UI developer: Maria Macias
8
+ Twitter: @maria_ux
9
+ From:Barcelona, Catalonia, Spain
10
+
11
+ One eyed illustrator: Carlos Mañas
12
+ Twitter: @oneeyedman
13
+ From:Madrid, Spain
14
+
15
+ Standard Man: Abel Cabans
16
+ Twitter: @abelcabans
17
+ From:Barcelona, Catalonia, Spain
18
+
19
+ Web designer: Abel Sutilo
20
+ Twitter: @abelsutilo
21
+ From:Sevilla, Andalucia, Spain
22
+
23
+ /* THANKS */
24
+
25
+ (First) EN Translator: Jos Flores
26
+ Twitter: @prosciuttos
27
+ From: Barcelona, Catalonia, Spain
28
+
29
+ CA Translator: Eva AC
30
+ Twitter: @evaac
31
+ From:Barcelona, Catalonia, Spain
32
+
33
+ EN Translator: Marta Armada
34
+ Twitter: @martuishere
35
+ From: Barcelona, Catalonia, Spain
36
+
37
+ RU Translator: Alexey Bass
38
+ Twitter: @alexey_bass
39
+ Location: Israel, Netanya
40
+
41
+ RU Translator: Vladimir Epifanov
42
+ Twitter: @voldmar
43
+ Location: Moscow, Russia
44
+
45
+ NL Translator: Rowdy Rabouw
46
+ Twitter: @rowdyrabouw
47
+ Location: Gouda, The Netherlands
48
+
49
+ DE Translator: Dennis Fischer
50
+ Twitter: @ichderfisch
51
+ Location: Düsseldorf / Germany
52
+
53
+ CZ Translator: Daniel Kršiak
54
+ Twitter: @krsiakdaniel
55
+ Location: Czech Republic
56
+
57
+ ZH Translator: Ana Villalba
58
+ Location: Spain
59
+
60
+ JA Translator: Clémence Haure
61
+ Location: Spain
62
+
63
+ FR Translator: Thibaud Desodt
64
+ Location: Belgium
65
+
66
+ Media Queries by: Marta Armada (@martuishere) and Javier Usobiaga (@htmlboy)
67
+
68
+
69
+ /* SITE */
70
+ Last update:2012/02/04
71
+ Language: Català / Czech / Deutsch / English / Castellano / Japanese / Dutch / Russian / Chinese
72
+ Doctype:HTML5
73
+ IDE: Sublime Text, Notepad++, FileZilla, Photoshop
@@ -7,18 +7,24 @@ describe "humans.rb" do
7
7
  end
8
8
 
9
9
  it "should return the string if passed" do
10
- expect(HumansRb.new("foo").body).to eql("foo")
10
+ expect(HumansRb.new("foo").body).to eql("foo\n")
11
11
  end
12
12
 
13
13
  it "should return the body if a URL is passed" do
14
14
  stub_request(:get, "http://ben.balter.com/humans.txt").
15
15
  to_return(:status => 200, :body => "foo", :headers => {})
16
16
 
17
- expect(HumansRb.new("http://ben.balter.com/humans.txt").body).to eql("foo")
17
+ expect(HumansRb.new("http://ben.balter.com/humans.txt").body).to eql("foo\n")
18
18
  end
19
19
 
20
20
  it "should return headings" do
21
21
  output = @humans.parse
22
22
  expect(output.count).to eql(2)
23
23
  end
24
+
25
+ it "should parse the humanstxt.org humans.txt file" do
26
+ humans = HumansRb.new(load_fixture("humansorg.txt")).parse
27
+ expect(humans).to_not be_nil
28
+ expect(humans[:team]).to_not be_nil
29
+ end
24
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: humans_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter
@@ -131,6 +131,7 @@ files:
131
131
  - script/console
132
132
  - script/release
133
133
  - spec/fixtures/humans.txt
134
+ - spec/fixtures/humansorg.txt
134
135
  - spec/humans_parser_spec.rb
135
136
  - spec/humans_rb_spec.rb
136
137
  - spec/humans_transform_spec.rb
@@ -161,6 +162,7 @@ specification_version: 4
161
162
  summary: A Ruby gem for parsing humans.txt files
162
163
  test_files:
163
164
  - spec/fixtures/humans.txt
165
+ - spec/fixtures/humansorg.txt
164
166
  - spec/humans_parser_spec.rb
165
167
  - spec/humans_rb_spec.rb
166
168
  - spec/humans_transform_spec.rb