humans_rb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.md +22 -0
- data/README.md +35 -0
- data/Rakefile +8 -0
- data/humans_rb.gemspec +28 -0
- data/lib/humans/parser.rb +31 -0
- data/lib/humans/transform.rb +23 -0
- data/lib/humans/version.rb +3 -0
- data/lib/humans.rb +26 -0
- data/script/bootstrap +3 -0
- data/script/cibuild +5 -0
- data/script/console +3 -0
- data/script/release +38 -0
- data/spec/fixtures/humans.txt +12 -0
- data/spec/humans_parser_spec.rb +199 -0
- data/spec/humans_rb_spec.rb +24 -0
- data/spec/humans_transform_spec.rb +25 -0
- data/spec/spec_helper.rb +20 -0
- metadata +167 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 23eb23b10bd8b468d79895cc4d10366847413d93
|
4
|
+
data.tar.gz: 03a17e007a29bb8643a2e32340dd24bf5128cc17
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 909d80dac1b89cd2889c122d245be9dfa7324127c878c9012d6f2549e5b2d164b42504499ed38b0ccf4681a06c50dee10b7f7cf3d2824eaa6db6024a2b8f3c32
|
7
|
+
data.tar.gz: cf2101978234a73850f2b93ada1d165a5816f7e821603abbf15cd0194773ec740f55025106c0d2baab1cfb88db1d38b2faf2608ae1331b6d9c944e82496b9b1a
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Ben Balter
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Humans.rb
|
2
|
+
|
3
|
+
A Ruby gem for parsing humans.txt files
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/benbalter/humans.rb.svg)](https://travis-ci.org/benbalter/humans.rb)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
1. Add `gem 'humans-rb'` to your project's Gemfile
|
10
|
+
2. `bundle install`
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
# Passing a domain (defaults to domain/humans.txt)
|
16
|
+
> HumansRb.new("http://ben.balter.com").parse
|
17
|
+
=> {
|
18
|
+
:site=> {
|
19
|
+
:"last updated"=>"2015/03/12",
|
20
|
+
:standards=>"HTML5, CSS3",
|
21
|
+
:components=> "jekyll, jekyll-coffeescript, jekyll-sass-converter, kramdown, maruku, rdiscount, redcarpet, RedCloth, liquid, pygments.rb, jemoji, jekyll-mentions, jekyll-redirect-from, jekyll-sitemap, github-pages, ruby"
|
22
|
+
},
|
23
|
+
:team=> {
|
24
|
+
:name=>"benbalter", :site=>"https://github.com/benbalter"},
|
25
|
+
:name=>"balterbot", :site=>"https://github.com/balterbot"}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
# Passing a URL
|
30
|
+
> HumansRb.new("http://ben.balter.com/humans.txt").parse
|
31
|
+
=> {:site=>..}
|
32
|
+
|
33
|
+
# Passing a string
|
34
|
+
> HumansRb.new("/* SITE */...").parse
|
35
|
+
```
|
data/Rakefile
ADDED
data/humans_rb.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'humans/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "humans_rb"
|
8
|
+
spec.version = HumansRb::VERSION
|
9
|
+
spec.authors = ["Ben Balter"]
|
10
|
+
spec.email = ["ben.balter@github.com"]
|
11
|
+
spec.summary = %q{A Ruby gem for parsing humans.txt files}
|
12
|
+
spec.homepage = "https://github.com/benbalter/humans.rb"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "typhoeus", "~> 0.7"
|
21
|
+
spec.add_dependency "parslet", "~> 1.6"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "webmock"
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class HumansRb::Parser < Parslet::Parser
|
2
|
+
rule(:space) { str(" ") }
|
3
|
+
rule(:space?) { space.repeat }
|
4
|
+
rule(:tab) { match("[\t]").repeat(1) }
|
5
|
+
rule(:tab?) { match("[\t]").repeat }
|
6
|
+
rule(:whitespace) { (space | tab).repeat(1) }
|
7
|
+
rule(:whitespace?) { (space | tab).repeat }
|
8
|
+
|
9
|
+
rule(:newline) { match("[\n]") >> whitespace? }
|
10
|
+
rule(:newline?) { newline.maybe }
|
11
|
+
|
12
|
+
rule(:slash_star) { str("/*") }
|
13
|
+
rule(:star_slash) { str("*/") }
|
14
|
+
rule(:heading_name) { newline.absent? >> space.absent? >> match("[A-Z]").repeat(1) }
|
15
|
+
rule(:heading) { slash_star >> space >> heading_name.as(:heading) >> space >> star_slash >> newline }
|
16
|
+
|
17
|
+
rule(:colon) { str(":") }
|
18
|
+
rule(:key) { slash_star.absent? >> newline.absent? >> match("[^:\n]").repeat.as(:key) >> colon }
|
19
|
+
rule(:value) { newline.absent? >> match("[^\n]").repeat.as(:value) }
|
20
|
+
rule(:key_value_pair) { whitespace? >> key >> space >> value >> newline }
|
21
|
+
rule(:key_value_pairs) { key_value_pair.repeat(1).as(:values) }
|
22
|
+
|
23
|
+
rule(:name) { slash_star.absent? >> match("[^\t\n:]").repeat(1).as(:name) >> newline }
|
24
|
+
rule(:team_member) { whitespace? >> name.maybe >> key_value_pair.repeat(1) >> newline? >> newline? }
|
25
|
+
rule(:team_members) { team_member.as(:member).repeat(2).as(:members) }
|
26
|
+
|
27
|
+
rule(:section) { heading >> newline? >> (team_members | key_value_pairs) >> newline? }
|
28
|
+
rule(:document) { section.repeat(1).as(:sections) }
|
29
|
+
|
30
|
+
root :document
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class HumansRb
|
2
|
+
class Transform < Parslet::Transform
|
3
|
+
rule(:sections => subtree(:sections)) do |dict|
|
4
|
+
dict[:sections].reduce(Hash.new, :merge)
|
5
|
+
end
|
6
|
+
|
7
|
+
rule(:heading => simple(:heading), :values => subtree(:values)) do |dict|
|
8
|
+
{ dict[:heading].to_s.downcase.to_sym => dict[:values].reduce(Hash.new, :merge) }
|
9
|
+
end
|
10
|
+
|
11
|
+
rule(:heading => simple(:heading), :members => subtree(:values)) do |dict|
|
12
|
+
{ dict[:heading].to_s.downcase.to_sym => dict[:values] }
|
13
|
+
end
|
14
|
+
|
15
|
+
rule(:member => subtree(:member)) do |dict|
|
16
|
+
dict[:member].reduce(Hash.new, :merge)
|
17
|
+
end
|
18
|
+
|
19
|
+
rule(:key => simple(:key), :value => subtree(:value)) do
|
20
|
+
{ key.to_s.downcase.to_sym => value.to_s }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/humans.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'typhoeus'
|
2
|
+
require 'parslet'
|
3
|
+
require "humans/version"
|
4
|
+
require "humans/parser"
|
5
|
+
require "humans/transform"
|
6
|
+
|
7
|
+
class HumansRb
|
8
|
+
def initialize(url_or_string)
|
9
|
+
@url_or_string = url_or_string
|
10
|
+
end
|
11
|
+
|
12
|
+
def body
|
13
|
+
if @url_or_string =~ /^http/
|
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
|
+
else
|
17
|
+
@url_or_string
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse
|
22
|
+
Transform.new.apply(Parser.new.parse(body))
|
23
|
+
rescue Parslet::ParseFailed => failure
|
24
|
+
puts failure.cause.ascii_tree
|
25
|
+
end
|
26
|
+
end
|
data/script/bootstrap
ADDED
data/script/cibuild
ADDED
data/script/console
ADDED
data/script/release
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
# Tag and push a release.
|
3
|
+
|
4
|
+
set -e
|
5
|
+
|
6
|
+
# Make sure we're in the project root.
|
7
|
+
|
8
|
+
cd $(dirname "$0")/..
|
9
|
+
|
10
|
+
# Build a new gem archive.
|
11
|
+
|
12
|
+
rm -rf humans_rb-*.gem
|
13
|
+
gem build -q humans_rb.gemspec
|
14
|
+
|
15
|
+
# Make sure we're on the master branch.
|
16
|
+
|
17
|
+
(git branch | grep -q '* master') || {
|
18
|
+
echo "Only release from the master branch."
|
19
|
+
exit 1
|
20
|
+
}
|
21
|
+
|
22
|
+
# Figure out what version we're releasing.
|
23
|
+
|
24
|
+
tag=v`ls humans_rb-*.gem | sed 's/^humans_rb-\(.*\)\.gem$/\1/'`
|
25
|
+
|
26
|
+
# Make sure we haven't released this version before.
|
27
|
+
|
28
|
+
git fetch -t origin
|
29
|
+
|
30
|
+
(git tag -l | grep -q "$tag") && {
|
31
|
+
echo "Whoops, there's already a '${tag}' tag."
|
32
|
+
exit 1
|
33
|
+
}
|
34
|
+
|
35
|
+
# Tag it and bag it.
|
36
|
+
|
37
|
+
gem push humans_rb-*.gem && git tag "$tag" &&
|
38
|
+
git push origin master && git push origin "$tag"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/* SITE */
|
2
|
+
Last Updated: 2015/03/12
|
3
|
+
Standards: HTML5, CSS3
|
4
|
+
Components: jekyll, jekyll-coffeescript, jekyll-sass-converter, kramdown, maruku, rdiscount, redcarpet, RedCloth, liquid, pygments.rb, jemoji, jekyll-mentions, jekyll-redirect-from, jekyll-sitemap, github-pages, ruby
|
5
|
+
|
6
|
+
/* TEAM */
|
7
|
+
|
8
|
+
Name: benbalter
|
9
|
+
Site: https://github.com/benbalter
|
10
|
+
|
11
|
+
Name: balterbot
|
12
|
+
Site: https://github.com/balterbot
|
@@ -0,0 +1,199 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe HumansRb::Parser do
|
4
|
+
let(:parser) { HumansRb::Parser.new }
|
5
|
+
|
6
|
+
context "spaces" do
|
7
|
+
let(:space_parser) { parser.space }
|
8
|
+
it "can detect a space" do
|
9
|
+
expect(space_parser).to parse(" ")
|
10
|
+
expect(space_parser).to_not parse("\n")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "newlines" do
|
15
|
+
let(:newline_parser) { parser.newline }
|
16
|
+
it "can detect a new line" do
|
17
|
+
expect(newline_parser).to parse("\n")
|
18
|
+
expect(newline_parser).to_not parse(" ")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "stars" do
|
23
|
+
let(:star_slash_parser) { parser.star_slash }
|
24
|
+
let(:slash_star_parser) { parser.slash_star }
|
25
|
+
|
26
|
+
it "can detect a star slash" do
|
27
|
+
expect(star_slash_parser).to parse("*/")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "can detect a slash star" do
|
31
|
+
expect(slash_star_parser).to parse("/*")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "heading parsing" do
|
36
|
+
let(:heading_parser) { parser.heading }
|
37
|
+
let(:heading_name_parser) { parser.heading_name }
|
38
|
+
|
39
|
+
it "parses the heading name" do
|
40
|
+
expect(heading_name_parser).to parse("TEST")
|
41
|
+
expect(heading_name_parser).to_not parse("TEST TEST")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "parses headings" do
|
45
|
+
expect(heading_parser).to parse("/* TEST */\n")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "key/value parsing" do
|
50
|
+
let(:key_value_parser) { parser.key_value_pair }
|
51
|
+
let(:colon_parser) { parser.colon }
|
52
|
+
let(:key_parser) { parser.key }
|
53
|
+
let(:value_parser) { parser.value }
|
54
|
+
|
55
|
+
it "detects colons" do
|
56
|
+
expect(colon_parser).to parse(":")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "detects keys" do
|
60
|
+
expect(key_parser).to parse("foo:")
|
61
|
+
expect(key_parser).to parse("foo bar:")
|
62
|
+
expect(key_parser).to_not parse("foo:\n")
|
63
|
+
expect(key_parser).to_not parse("foo: ")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "detects values" do
|
67
|
+
expect(value_parser).to parse("foo bar")
|
68
|
+
expect(value_parser).to_not parse("foo \nbar")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "parses key/value pairs" do
|
72
|
+
expect(key_value_parser).to parse("foo: bar\n")
|
73
|
+
expect(key_value_parser).to parse("foo: bar\n")
|
74
|
+
expect(key_value_parser).to parse("foo foo: bar\n")
|
75
|
+
end
|
76
|
+
|
77
|
+
it "parses key value pairs with leading whitespace" do
|
78
|
+
expect(key_value_parser).to parse(" foo: bar\n")
|
79
|
+
expect(key_value_parser).to parse("\tfoo: bar\n")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "teams" do
|
84
|
+
let(:name_parser) { parser.name }
|
85
|
+
let(:team_member_parser) { parser.team_member }
|
86
|
+
let(:team_members_parser) { parser.team_members }
|
87
|
+
|
88
|
+
it "detects a team member" do
|
89
|
+
expect(team_member_parser).to parse("key: value\nkey2: value2\n\n")
|
90
|
+
end
|
91
|
+
|
92
|
+
it "detects GitHub-style names" do
|
93
|
+
expect(name_parser).to parse("Ben Balter\n")
|
94
|
+
end
|
95
|
+
|
96
|
+
it "detects Github-style team members" do
|
97
|
+
input = <<-text
|
98
|
+
Jesse Newland
|
99
|
+
Site: https://github.com/jnewland
|
100
|
+
Location: San Francisco, CA
|
101
|
+
|
102
|
+
text
|
103
|
+
expect(team_member_parser).to parse(input)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "detects teams" do
|
107
|
+
input = <<-text
|
108
|
+
Name: benbalter
|
109
|
+
Site: https://github.com/benbalter
|
110
|
+
|
111
|
+
Name: balterbot
|
112
|
+
Site: https://github.com/balterbot
|
113
|
+
text
|
114
|
+
expect(team_members_parser).to parse(input)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "detects GitHub-style humans.txt teams" do
|
118
|
+
input = <<-text
|
119
|
+
Jesse Newland
|
120
|
+
Site: https://github.com/jnewland
|
121
|
+
Location: San Francisco, CA
|
122
|
+
|
123
|
+
Justin Palmer
|
124
|
+
Site: https://github.com/Caged
|
125
|
+
Location: Portland, OR
|
126
|
+
|
127
|
+
Sonya Green
|
128
|
+
Site: https://github.com/sundaykofax
|
129
|
+
|
130
|
+
|
131
|
+
Lee Reilly
|
132
|
+
Site: https://github.com/leereilly
|
133
|
+
Location: San Francisco, CA
|
134
|
+
text
|
135
|
+
expect(team_members_parser).to parse(input)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "section parsing" do
|
140
|
+
let(:section_parser) { parser.section }
|
141
|
+
|
142
|
+
it "parses sctions" do
|
143
|
+
expect(section_parser).to parse("/* TEST */\nkey: value\n")
|
144
|
+
expect(section_parser).to parse("/* TEST */\n\nkey: value\n")
|
145
|
+
end
|
146
|
+
|
147
|
+
it "parses sctions with tabs" do
|
148
|
+
expect(section_parser).to parse("/* TEST */\n\tkey: value\n")
|
149
|
+
expect(section_parser).to parse("/* TEST */\n\n\tkey: value\n")
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should parse a TEAM section" do
|
153
|
+
input = <<-text
|
154
|
+
/* TEAM */
|
155
|
+
Name: benbalter
|
156
|
+
Site: https://github.com/benbalter
|
157
|
+
|
158
|
+
Name: balterbot
|
159
|
+
Site: https://github.com/balterbot
|
160
|
+
text
|
161
|
+
expect(section_parser).to parse(input)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context "document" do
|
166
|
+
let(:document_parser) { parser.document }
|
167
|
+
|
168
|
+
it "parses multiple sections" do
|
169
|
+
input = <<-text
|
170
|
+
/* SITE */
|
171
|
+
Last Updated: 2015/03/12
|
172
|
+
Standards: HTML5, CSS3
|
173
|
+
|
174
|
+
/* TEAM */
|
175
|
+
Name: benbalter
|
176
|
+
Site: https://github.com/benbalter
|
177
|
+
|
178
|
+
text
|
179
|
+
expect(document_parser).to parse(input)
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should parse ben.balter.com's humans.txt" do
|
183
|
+
input = <<-text
|
184
|
+
/* SITE */
|
185
|
+
Last Updated: 2015/03/12
|
186
|
+
Standards: HTML5, CSS3
|
187
|
+
|
188
|
+
/* TEAM */
|
189
|
+
|
190
|
+
Name: benbalter
|
191
|
+
Site: https://github.com/benbalter
|
192
|
+
|
193
|
+
Name: balterbot
|
194
|
+
Site: https://github.com/balterbot
|
195
|
+
text
|
196
|
+
expect(document_parser).to parse(input)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "humans.rb" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@humans = HumansRb.new load_fixture("humans.txt")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return the string if passed" do
|
10
|
+
expect(HumansRb.new("foo").body).to eql("foo")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return the body if a URL is passed" do
|
14
|
+
stub_request(:get, "http://ben.balter.com/humans.txt").
|
15
|
+
to_return(:status => 200, :body => "foo", :headers => {})
|
16
|
+
|
17
|
+
expect(HumansRb.new("http://ben.balter.com/humans.txt").body).to eql("foo")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return headings" do
|
21
|
+
output = @humans.parse
|
22
|
+
expect(output.count).to eql(2)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe HumansRb::Transform do
|
4
|
+
let(:xform) { HumansRb::Transform.new }
|
5
|
+
|
6
|
+
context "values" do
|
7
|
+
it "transform the key/value pair values" do
|
8
|
+
expected = { :foo => "bar" }
|
9
|
+
expect(xform.apply({ :key => "foo", :value => "bar" })).to eq(expected)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "merges the array of hashes into a single hash" do
|
13
|
+
input = { :heading => "test", :values => [{ :foo => "bar"}, {:foo2 => "bar2" }] }
|
14
|
+
expected = { :foo => "bar", :foo2 => "bar2" }
|
15
|
+
expect(xform.apply(input)[:test]).to eq(expected)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "headings" do
|
20
|
+
it "converts the heading" do
|
21
|
+
input = { :heading => "test", :values => [{ :foo => "bar"}, {:foo2 => "bar2" }] }
|
22
|
+
expect(xform.apply(input).keys.first).to eq(:test)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "parslet/rig/rspec"
|
3
|
+
|
4
|
+
ENV['RACK_ENV'] = 'test'
|
5
|
+
$:.push File.join(File.dirname(__FILE__), '..', 'lib')
|
6
|
+
|
7
|
+
require 'webmock/rspec'
|
8
|
+
|
9
|
+
require_relative "../lib/humans"
|
10
|
+
|
11
|
+
WebMock.disable_net_connect!
|
12
|
+
|
13
|
+
def fixtures_dir
|
14
|
+
File.expand_path("./fixtures", File.dirname(__FILE__))
|
15
|
+
end
|
16
|
+
|
17
|
+
def load_fixture(fixture)
|
18
|
+
path = File.expand_path(fixture, fixtures_dir)
|
19
|
+
File.open(path).read
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: humans_rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Balter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: typhoeus
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: parslet
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- ben.balter@github.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.md
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- humans_rb.gemspec
|
125
|
+
- lib/humans.rb
|
126
|
+
- lib/humans/parser.rb
|
127
|
+
- lib/humans/transform.rb
|
128
|
+
- lib/humans/version.rb
|
129
|
+
- script/bootstrap
|
130
|
+
- script/cibuild
|
131
|
+
- script/console
|
132
|
+
- script/release
|
133
|
+
- spec/fixtures/humans.txt
|
134
|
+
- spec/humans_parser_spec.rb
|
135
|
+
- spec/humans_rb_spec.rb
|
136
|
+
- spec/humans_transform_spec.rb
|
137
|
+
- spec/spec_helper.rb
|
138
|
+
homepage: https://github.com/benbalter/humans.rb
|
139
|
+
licenses:
|
140
|
+
- MIT
|
141
|
+
metadata: {}
|
142
|
+
post_install_message:
|
143
|
+
rdoc_options: []
|
144
|
+
require_paths:
|
145
|
+
- lib
|
146
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
requirements: []
|
157
|
+
rubyforge_project:
|
158
|
+
rubygems_version: 2.2.0
|
159
|
+
signing_key:
|
160
|
+
specification_version: 4
|
161
|
+
summary: A Ruby gem for parsing humans.txt files
|
162
|
+
test_files:
|
163
|
+
- spec/fixtures/humans.txt
|
164
|
+
- spec/humans_parser_spec.rb
|
165
|
+
- spec/humans_rb_spec.rb
|
166
|
+
- spec/humans_transform_spec.rb
|
167
|
+
- spec/spec_helper.rb
|