semantic-mapper 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 46b303dae82c792ec2862601fe90808952ad1edc
4
+ data.tar.gz: 6db10dedf96e9452019b78ab59d536f439fd9716
5
+ SHA512:
6
+ metadata.gz: e446c85df5964880d649a99ec244f025c2475c525964264f633cf287608710cdedfea7cb8b21650edbbafa42b387f5e12ad100c8c483cf9b3a384df43482d599
7
+ data.tar.gz: 79cc02ecb606559ff3c4e9f637e1bf4b5f5bb0840c8c00457f8d1d84db1f91cd0f1c9ee1dc83284cf01c2cc7ef8bf3c42cf3c5a070d536cf75f8c86433d28d34
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1 @@
1
+ 2.1.5
data/.travis ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in semantic-mapper.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Perry Hertler
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.
@@ -0,0 +1,49 @@
1
+ # Semantic::Mapper
2
+
3
+ Takes some markup of the form:
4
+ ```html
5
+ <div class="p-author h-card">
6
+ <div class="form-field">
7
+ <label for="p-first-name" class="required">First Name</label>
8
+ <input type="text" id="p-first-name" class="p-first-name" name="p-first-name" data-mapping="first_name" required>
9
+ </div>
10
+
11
+ <div class="form-field">
12
+ <label for="p-last-name" class="required">Last Name</label>
13
+ <input type="text" id="p-last-name" class="p-last-name" name="p-last-name" data-mapping="last_name" required>
14
+ </div>
15
+ </div>
16
+ ```
17
+
18
+ and returns an indifferent hash of the form:
19
+ ```ruby
20
+ {first_name: 'p-first-name', last_name: 'p-last-name'}
21
+ ```
22
+
23
+ ## Installation
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ ```ruby
28
+ gem 'semantic-mapper'
29
+ ```
30
+
31
+ And then execute:
32
+
33
+ $ bundle
34
+
35
+ Or install it yourself as:
36
+
37
+ $ gem install semantic-mapper
38
+
39
+ ## Usage
40
+
41
+ TODO: Write usage instructions here
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( https://github.com/[my-github-username]/semantic-mapper/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,11 @@
1
+ require 'nokogiri'
2
+ require 'active_support/core_ext/object/try'
3
+ require 'active_support/core_ext/hash'
4
+
5
+ module Semantic
6
+ module Mapper
7
+ # Your code goes here...
8
+ end
9
+ end
10
+ require 'semantic/mapper/version'
11
+ require 'semantic/mapper/markup'
@@ -0,0 +1,28 @@
1
+ module Semantic
2
+ module Mapper
3
+ class Markup
4
+ SELECTOR = '[data-mapping]'
5
+
6
+ def initialize(html)
7
+ @html = html
8
+ end
9
+
10
+ def map
11
+ document.css(SELECTOR).inject({}) do |hash, element|
12
+ hash[attribute_value(element, 'data-mapping')] = attribute_value(element, 'name')
13
+ hash
14
+ end.with_indifferent_access
15
+ end
16
+
17
+ private
18
+ def document
19
+ @document ||= Nokogiri::HTML(@html)
20
+ end
21
+
22
+ def attribute_value(element, attribute_name)
23
+ element.attributes[attribute_name].try(:value)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,5 @@
1
+ module Semantic
2
+ module Mapper
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'semantic/mapper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'semantic-mapper'
8
+ spec.version = Semantic::Mapper::VERSION
9
+ spec.authors = ['Perry Hertler']
10
+ spec.email = ['perry@hertler.org']
11
+ spec.summary = %q{Map semantic inputs to expected API params.}
12
+ spec.description = %q{Map semantic inputs to expected API params.}
13
+ spec.homepage = ""
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'pry-nav'
24
+ spec.add_development_dependency 'rspec', '~> 3.1'
25
+ spec.add_development_dependency 'rspec-its'
26
+
27
+ spec.add_dependency 'nokogiri'
28
+ spec.add_dependency 'activesupport'
29
+ end
@@ -0,0 +1,115 @@
1
+ <div class="p-author h-card">
2
+ <div class="form-field">
3
+ <label for="p-first-name" class="required">First Name</label>
4
+ <input type="text" id="p-first-name" class="p-first-name" name="p-first-name" data-mapping="first_name" required>
5
+ </div>
6
+
7
+ <div class="form-field">
8
+ <label for="p-last-name" class="required">Last Name</label>
9
+ <input type="text" id="p-last-name" class="p-last-name" name="p-last-name" data-mapping="last_name" required>
10
+ </div>
11
+
12
+ <div class="form-field">
13
+ <label for="p-address1" class="required">Address</label>
14
+ <input type="text" id="p-address1" class="p-address1" name="p-address1" data-mapping="address1" required>
15
+ </div>
16
+
17
+ <div class="form-field">
18
+ <label for="p-city" class="required">City</label>
19
+ <input type="text" id="p-city" class="p-city" name="p-city" data-mapping="city" required>
20
+ </div>
21
+
22
+ <div class="form-field">
23
+ <label for="p-state" class="required">State</label>
24
+ <input type="text" id="p-state" class="p-state" name="p-state" data-mapping="region" required>
25
+ </div>
26
+
27
+ <div class="form-field">
28
+ <label for="p-postal-code" class="required">Zip</label>
29
+ <input type="text" id="p-postal-code" class="p-postal-code" name="p-postal-code" data-mapping="postal_code" required>
30
+ </div>
31
+
32
+ <div class="form-field">
33
+ <label for="p-tel">Phone Number</label>
34
+ <input type="tel" id="p-tel" class="p-tel" name="p-tel" data-mapping="phone">
35
+ </div>
36
+
37
+ <div class="form-field">
38
+ <label for="u-email" class="required">Email</label>
39
+ <input type="email" id="u-email" class="u-email" name="u-email" data-mapping="email" required>
40
+ </div>
41
+
42
+ <div class="form-field">
43
+ <label for="p-card-type" class="required">Card Type</label>
44
+ <select id="p-card-type" class="p-card-type" name="p-card-type" data-mapping="credit_card_type" required>
45
+ <option value="visa">Visa</option>
46
+ <option value="mastercard">Mastercard</option>
47
+ <option value="discover">Discover</option>
48
+ <option value="amex">Amex</option>
49
+ </select>
50
+ </div>
51
+
52
+ <div class="form-field">
53
+ <label for="p-card-number" class="required">Card #</label>
54
+ <input type="text" id="p-card-number" class="p-card-number" name="p-card-number" title="Credit Card (Numbers only, no spaces or dashes)" size="20" maxlength="16" placeholder="Credit Card (No spaces no dashes)" autocomplete="off" pattern="[0-9]{13,16}" data-mapping="credit_card_number"
55
+ required>
56
+ </div>
57
+
58
+ <div class="form-field">
59
+ <label for="p-cvv-number" class="required">CVV#</label>
60
+ <input type="text" id="p-cvv-number" class="p-cvv-number" name="p-cvv-number" title="CVV (Numbers only, 3 or 4 digit security code)" size="4" maxlength="4" placeholder="XXX" pattern="[0-9]{3,4}" autocomplete="off" data-mapping="credit_card_cvv_number" required>
61
+ </div>
62
+
63
+ <div class="form-field">
64
+ <label for="p-card-exp-month" class="required">Expiration Date:</label>
65
+ <select id="p-card-exp-month" class="p-card-exp-month" name="p-card-exp-month" data-mapping="credit_card_exp_month" required>
66
+ <option value="1">1 - January</option>
67
+ <option value="2">2 - February</option>
68
+ <option value="3">3 - March</option>
69
+ <option value="4">4 - April</option>
70
+ <option value="5">5 - May</option>
71
+ <option value="6">6 - June</option>
72
+ <option value="7">7 - July</option>
73
+ <option value="8">8 - August</option>
74
+ <option value="9">9 - September</option>
75
+ <option value="10">10 - October</option>
76
+ <option value="11">11 - November</option>
77
+ <option value="12">12 - December</option>
78
+ </select>
79
+ <select id="p-card-exp-year" class="p-card-exp-year" name="p-card-exp-year" data-mapping="credit_card_exp_year">
80
+ <option value="2014">2015</option>
81
+ <option value="2015">2016</option>
82
+ <option value="2016">2017</option>
83
+ <option value="2017">2018</option>
84
+ <option value="2018">2019</option>
85
+ </select>
86
+ </div>
87
+ </div>
88
+
89
+ <div class="form-field">
90
+ <label for="e-content">Message (250 character limit)</label>
91
+ <textarea id="e-content" class="e-content" name="e-content" maxlength="250" data-mapping="message"></textarea>
92
+ </div>
93
+
94
+ <div class="form-field">
95
+ <label for="p-storage-unit-external-id" class="required">storage_unit_external_id</label>
96
+ <input type="text" id="p-storage-unit-external-id" class="p-storage-unit-external-id" name="p-storage-unit-external-id" data-mapping="storage_unit_external_id" required>
97
+ </div>
98
+
99
+ <div class="form-field">
100
+ <label for="p-rental-rate" class="required">Rental Rate</label>
101
+ <input type="text" id="p-rental-rate" class="p-rental-rate" name="p-rental-rate" data-mapping="rental_rate" required>
102
+ </div>
103
+
104
+ <div class="form-field">
105
+ <label for="p-reservation-date" class="required">Desired Move-In Date</label>
106
+ <input type="date" id="p-reservation-date" class="p-reservation-date" name="p-reservation-date" data-mapping="reservation_date" required>
107
+ </div>
108
+
109
+ <div class="form-field">
110
+ <label for="p-time-zone" class="required">Time Zone</label>
111
+ <input type="text" id="p-time-zone" class="p-time-zone" name="p-time-zone" data-mapping="time_zone" required>
112
+ </div>
113
+
114
+ <input type="submit" value="Send" />
115
+ <span class="form-instruction">* Required Field</span>
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Semantic::Mapper::Markup do
4
+ let(:markup) { Semantic::Mapper::Markup.new(html) }
5
+ let(:html) { fixture('reservation.html') }
6
+
7
+ describe :map do
8
+ subject { markup.map }
9
+
10
+ its([:first_name]) { is_expected.to eq('p-first-name') }
11
+ its([:last_name]) { is_expected.to eq('p-last-name') }
12
+ its([:credit_card_type]) { is_expected.to eq('p-card-type') }
13
+ its([:credit_card_exp_month]) { is_expected.to eq('p-card-exp-month') }
14
+ its([:message]) { is_expected.to eq('e-content') }
15
+ its([:storage_unit_external_id]) { is_expected.to eq('p-storage-unit-external-id') }
16
+ its([:rental_rate]) { is_expected.to eq('p-rental-rate') }
17
+ its([:reservation_date]) { is_expected.to eq('p-reservation-date') }
18
+ its([:time_zone]) { is_expected.to eq('p-time-zone') }
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ require 'pry'
2
+ require 'rspec/its'
3
+
4
+ module FixturesHelper
5
+ def fixture(fixture_path)
6
+ open(File.join("spec", "fixtures", fixture_path)).read
7
+ end
8
+ end
9
+
10
+ RSpec.configure do |config|
11
+ config.include FixturesHelper
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+
15
+ config.order = 'random'
16
+ end
17
+
18
+ require 'semantic/mapper'
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: semantic-mapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Perry Hertler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-nav
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-its
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: nokogiri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
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: activesupport
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Map semantic inputs to expected API params.
112
+ email:
113
+ - perry@hertler.org
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".ruby-version"
120
+ - ".travis"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - lib/semantic/mapper.rb
126
+ - lib/semantic/mapper/markup.rb
127
+ - lib/semantic/mapper/version.rb
128
+ - semantic-mapper.gemspec
129
+ - spec/fixtures/reservation.html
130
+ - spec/lib/semantic/mapper/markup_spec.rb
131
+ - spec/spec_helper.rb
132
+ homepage: ''
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.2.2
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Map semantic inputs to expected API params.
156
+ test_files:
157
+ - spec/fixtures/reservation.html
158
+ - spec/lib/semantic/mapper/markup_spec.rb
159
+ - spec/spec_helper.rb