table_syntax 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1f5b26e2f3a21cc1ba1f1f0d77076ef6536dc500
4
+ data.tar.gz: 4a0dc3d9fe4d7fbacf8e0ff154bb94f1d8455469
5
+ SHA512:
6
+ metadata.gz: ed5af7cee70534337953bd88b8e4e63cd97c9925e07072a89935aaf81d08781e891a2036e03f36ecea8ba5580bbbe6efee78a468a76d97c9d42e04822b35045a
7
+ data.tar.gz: be7c3498ab7f1a7c8da35a679adb6616af6663acfab001048d67871041b152752bded7c46f164a69addf23aae921325e7c35e1ca3f399e81667a3f30994f1620
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ - 2.1
5
+ before_install: gem install bundler
6
+ addons:
7
+ code_climate:
8
+ repo_token: 03c3223e71ee576214676d744a9ad4172a70b40cb2dfbcb492cdf31fdd9c2617
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in table_syntax.gemspec
4
+ gemspec
5
+
6
+ gem 'codeclimate-test-reporter', group: :test, require: nil
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2012 tomykaira
4
+ Copyright (c) 2015 Jan Vlnas
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
@@ -0,0 +1,65 @@
1
+ # TableSyntax
2
+
3
+ TableSyntax was extracted from [RSpec::Parameterized](https://github.com/tomykaira/rspec-parameterized) by [@tomykaira](https://github.com/tomykaira).
4
+
5
+ It lets you build tables in plain Ruby with simple syntax, like:
6
+
7
+ ```ruby
8
+ 'value1' | 123 | 'lorem'
9
+ 'value2' | 456 | 'ipsum'
10
+ :another | 'value' | [:dolor]
11
+ ```
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'table_syntax'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install table_syntax
28
+
29
+ ## Usage
30
+
31
+ `TableSyntax` exposes method `.build`, which accepts column headers as arguments and block for table:
32
+
33
+ ```ruby
34
+ require 'table_syntax'
35
+
36
+ table = TableSyntax.build(:col1, :col2) do
37
+ 'value1' | 'value2'
38
+ :val3 | :val4
39
+ end
40
+ ```
41
+
42
+ The resulting table can be iterated, where each row is available in a Struct:
43
+
44
+ ```ruby
45
+ table.each do |row|
46
+ row.col1 # => 'value1'; :val3
47
+ row.col2 # => 'value2'; :val4
48
+ end
49
+ ```
50
+
51
+ ## Development
52
+
53
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
54
+
55
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at [jnv/table_syntax](https://github.com/jnv/table_syntax). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](https://contributor-covenant.org) code of conduct.
60
+
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
65
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "table_syntax"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ require "table_syntax/version"
2
+ require "table_syntax/table_parser"
3
+ require "table_syntax/header_table"
4
+
5
+ module TableSyntax
6
+
7
+ def self.build(*headers, &blk)
8
+ table = TableParser.parse(blk)
9
+ HeaderTable.new(headers, table)
10
+ end
11
+
12
+ end
@@ -0,0 +1,20 @@
1
+ module TableSyntax
2
+ class HeaderTable
3
+ include Enumerable
4
+
5
+ def initialize(headers, table)
6
+ unless headers.all? {|h| h.kind_of?(Symbol) }
7
+ raise ArgumentError, "All headers must be symbols"
8
+ end
9
+ @struct = Struct.new(*headers)
10
+ @rows = table.to_a
11
+ end
12
+
13
+ def each
14
+ return enum_for(:each) unless block_given?
15
+ @rows.each do |row|
16
+ yield @struct.new(*row)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,62 @@
1
+ #
2
+ # Based on RSpec::Parameterized::ExampleGroupMethods from https://github.com/tomykaira/rspec-parameterized
3
+ # Copyright 2012-2015 tomykaira
4
+ #
5
+ require 'parser'
6
+ require 'unparser'
7
+ require 'proc_to_ast'
8
+
9
+ module TableSyntax
10
+ module TableParser
11
+ module_function
12
+
13
+ #
14
+ # Separates table-like block of code from AST
15
+ #
16
+ def parse(block)
17
+ ast = block.to_ast
18
+ # produces sth. like:
19
+ # (block
20
+ # (send ..)
21
+ # (args)
22
+ # (begin ..)
23
+ # )
24
+ inner_ast = ast.children[2] # pick up (begin..)
25
+ if inner_ast.type == :send
26
+ lines = [inner_ast]
27
+ else
28
+ lines = inner_ast.children
29
+ end
30
+
31
+ lines.map do |node|
32
+ if node.type == :send
33
+ buf = []
34
+ extract_value(node, buf)
35
+ buf.reverse
36
+ end
37
+ end
38
+ end
39
+
40
+ def extract_value(node, buf)
41
+ receiver, method, arg = node.children
42
+
43
+ if method == :|
44
+ buf << eval_source_fragment(Unparser.unparse(arg))
45
+ end
46
+
47
+ if receiver.is_a?(AST::Node) && receiver.type == :send && receiver.children[1] == :|
48
+ extract_value(receiver, buf)
49
+ else
50
+ buf << eval_source_fragment(Unparser.unparse(receiver))
51
+ end
52
+ end
53
+
54
+ def eval_source_fragment(source_fragment)
55
+ instance = Object.new # for evaluate let methods.
56
+ if defined?(self.superclass::LetDefinitions)
57
+ instance.extend self.superclass::LetDefinitions
58
+ end
59
+ instance.instance_eval(source_fragment)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ module TableSyntax
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'table_syntax/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "table_syntax"
8
+ spec.version = TableSyntax::VERSION
9
+ spec.authors = ["Jan Vlnas", "tomykaira"]
10
+ spec.email = ["rubygems@jan.vlnas.cz"]
11
+
12
+ spec.summary = %q{Create hashes comfortably from data tables in Ruby.}
13
+ spec.description = %q{Use TableSyntax to create and parse data tables directly in Ruby code. Extracted from tomykaira's [RSpec::Parameterized](https://rubygems.org/gems/rspec-parameterized).}
14
+ spec.homepage = "https://github.com/jnv/table_syntax"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "parser"
23
+ spec.add_dependency "unparser"
24
+ spec.add_dependency "proc_to_ast"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.10"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest"
29
+ spec.add_development_dependency "minitest-reporters"
30
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: table_syntax
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jan Vlnas
8
+ - tomykaira
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2015-07-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: parser
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: unparser
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: proc_to_ast
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: bundler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.10'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.10'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '10.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '10.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: minitest
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: minitest-reporters
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ description: Use TableSyntax to create and parse data tables directly in Ruby code.
113
+ Extracted from tomykaira's [RSpec::Parameterized](https://rubygems.org/gems/rspec-parameterized).
114
+ email:
115
+ - rubygems@jan.vlnas.cz
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".gitignore"
121
+ - ".travis.yml"
122
+ - CODE_OF_CONDUCT.md
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - lib/table_syntax.rb
130
+ - lib/table_syntax/header_table.rb
131
+ - lib/table_syntax/table_parser.rb
132
+ - lib/table_syntax/version.rb
133
+ - table_syntax.gemspec
134
+ homepage: https://github.com/jnv/table_syntax
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.4.5
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Create hashes comfortably from data tables in Ruby.
158
+ test_files: []