inputomatic 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +85 -0
- data/README.md +8 -0
- data/Rakefile +1 -1
- data/lib/inputomatic/arithmetic_interpreter.rb +76 -0
- data/lib/inputomatic/date_time.rb +14 -0
- data/lib/inputomatic/number.rb +7 -0
- data/lib/inputomatic/version.rb +1 -1
- data/lib/inputomatic.rb +3 -87
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6295f84be5f085a1d760f6a3422aa158eac07a281f19ac28b7a0073c9a246006
|
4
|
+
data.tar.gz: c4e2007df2ef1cb736564da3c776d829c5eee7f87cbdf4120877688060998569
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64b8dc9da7ac89555a0b90b1d7de3abaec7e80fc14135ea89a4e0efe1ba0c03c3a8a38836c06a51c911aab77c02ade722211a1c263bc51e26125c899a4adea1f
|
7
|
+
data.tar.gz: 4e2791fe447ddfd6afcdd7d06e221c7711ab5e7c5075329ccf6e8786b769702aa3b6776a9d05ce183c0ab3b2b150b989f10a665bd47b264c1498040e838bbc82
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
inputomatic (0.1.0)
|
5
|
+
chronic (~> 0.10)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (7.0.4.3)
|
11
|
+
activesupport (= 7.0.4.3)
|
12
|
+
activerecord (7.0.4.3)
|
13
|
+
activemodel (= 7.0.4.3)
|
14
|
+
activesupport (= 7.0.4.3)
|
15
|
+
activesupport (7.0.4.3)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 1.6, < 2)
|
18
|
+
minitest (>= 5.1)
|
19
|
+
tzinfo (~> 2.0)
|
20
|
+
ast (2.4.2)
|
21
|
+
chronic (0.10.2)
|
22
|
+
concurrent-ruby (1.2.2)
|
23
|
+
diff-lcs (1.5.0)
|
24
|
+
i18n (1.12.0)
|
25
|
+
concurrent-ruby (~> 1.0)
|
26
|
+
json (2.6.3)
|
27
|
+
language_server-protocol (3.17.0.3)
|
28
|
+
minitest (5.18.0)
|
29
|
+
parallel (1.22.1)
|
30
|
+
parser (3.2.2.0)
|
31
|
+
ast (~> 2.4.1)
|
32
|
+
rainbow (3.1.1)
|
33
|
+
rake (13.0.6)
|
34
|
+
regexp_parser (2.7.0)
|
35
|
+
rexml (3.2.5)
|
36
|
+
rspec (3.12.0)
|
37
|
+
rspec-core (~> 3.12.0)
|
38
|
+
rspec-expectations (~> 3.12.0)
|
39
|
+
rspec-mocks (~> 3.12.0)
|
40
|
+
rspec-core (3.12.1)
|
41
|
+
rspec-support (~> 3.12.0)
|
42
|
+
rspec-expectations (3.12.2)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.12.0)
|
45
|
+
rspec-mocks (3.12.5)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.12.0)
|
48
|
+
rspec-support (3.12.0)
|
49
|
+
rubocop (1.48.1)
|
50
|
+
json (~> 2.3)
|
51
|
+
parallel (~> 1.10)
|
52
|
+
parser (>= 3.2.0.0)
|
53
|
+
rainbow (>= 2.2.2, < 4.0)
|
54
|
+
regexp_parser (>= 1.8, < 3.0)
|
55
|
+
rexml (>= 3.2.5, < 4.0)
|
56
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
57
|
+
ruby-progressbar (~> 1.7)
|
58
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
59
|
+
rubocop-ast (1.28.0)
|
60
|
+
parser (>= 3.2.1.0)
|
61
|
+
rubocop-performance (1.16.0)
|
62
|
+
rubocop (>= 1.7.0, < 2.0)
|
63
|
+
rubocop-ast (>= 0.4.0)
|
64
|
+
ruby-progressbar (1.13.0)
|
65
|
+
standard (1.26.0)
|
66
|
+
language_server-protocol (~> 3.17.0.2)
|
67
|
+
rubocop (~> 1.48.1)
|
68
|
+
rubocop-performance (~> 1.16.0)
|
69
|
+
tzinfo (2.0.6)
|
70
|
+
concurrent-ruby (~> 1.0)
|
71
|
+
unicode-display_width (2.4.2)
|
72
|
+
|
73
|
+
PLATFORMS
|
74
|
+
arm64-darwin-22
|
75
|
+
x86_64-linux
|
76
|
+
|
77
|
+
DEPENDENCIES
|
78
|
+
activerecord
|
79
|
+
inputomatic!
|
80
|
+
rake (~> 13.0)
|
81
|
+
rspec (~> 3.0)
|
82
|
+
standard (~> 1.3)
|
83
|
+
|
84
|
+
BUNDLED WITH
|
85
|
+
2.4.8
|
data/README.md
CHANGED
@@ -35,6 +35,14 @@ class Expense < ApplicationRecord
|
|
35
35
|
end
|
36
36
|
```
|
37
37
|
|
38
|
+
## Further reading
|
39
|
+
|
40
|
+
Learn more about Inputomatic.
|
41
|
+
|
42
|
+
* [Humane Rails Forms](https://fly.io/ruby-dispatch/humane-rails-forms/) - Article about how forms can be made more humane in Rails with inputomatic.
|
43
|
+
* [Demo App](https://inputomatic-demo.fly.dev) - Demo rails app where you can try the form fields
|
44
|
+
* [Demo App Repo](https://github.com/rocketshipio/inputomatic-demo) - Source code of demo app
|
45
|
+
|
38
46
|
## Development
|
39
47
|
|
40
48
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
@@ -0,0 +1,76 @@
|
|
1
|
+
module Inputomatic
|
2
|
+
class ArithmeticInterpreter
|
3
|
+
CURRENCY_SYMBOLS = "$£¢€¥₩₪₹₫₴₱₲₳₵₸₺₼₽៛₠₡₢₣₤₥₦₧₨₩₪₫€₭₮₯₰₱₲₳₴₵₶₷₸₹₺₻₼₽₾₿ℳ".chars.freeze
|
4
|
+
|
5
|
+
def initialize(input, decimal_separator: '.', thousands_separator: ',')
|
6
|
+
@input = input
|
7
|
+
.gsub(/\s+/, '')
|
8
|
+
.gsub(thousands_separator, '')
|
9
|
+
.gsub(Regexp.union(CURRENCY_SYMBOLS), '')
|
10
|
+
@decimal_separator = decimal_separator
|
11
|
+
@index = 0
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse
|
15
|
+
result = expression
|
16
|
+
if @index < @input.length
|
17
|
+
raise "Unexpected character: #{@input[@index]}"
|
18
|
+
end
|
19
|
+
result
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def expression
|
25
|
+
result = term
|
26
|
+
while @index < @input.length
|
27
|
+
case @input[@index]
|
28
|
+
when '+'
|
29
|
+
@index += 1
|
30
|
+
result += term
|
31
|
+
when '-'
|
32
|
+
@index += 1
|
33
|
+
result -= term
|
34
|
+
else
|
35
|
+
break
|
36
|
+
end
|
37
|
+
end
|
38
|
+
result
|
39
|
+
end
|
40
|
+
|
41
|
+
def term
|
42
|
+
result = factor
|
43
|
+
while @index < @input.length
|
44
|
+
case @input[@index]
|
45
|
+
when '*'
|
46
|
+
@index += 1
|
47
|
+
result *= factor
|
48
|
+
when '/'
|
49
|
+
@index += 1
|
50
|
+
result /= factor
|
51
|
+
else
|
52
|
+
break
|
53
|
+
end
|
54
|
+
end
|
55
|
+
result
|
56
|
+
end
|
57
|
+
|
58
|
+
def factor
|
59
|
+
if @input[@index] == '('
|
60
|
+
@index += 1
|
61
|
+
result = expression
|
62
|
+
if @input[@index] != ')'
|
63
|
+
raise "Expected ')'"
|
64
|
+
end
|
65
|
+
@index += 1
|
66
|
+
else
|
67
|
+
start_index = @index
|
68
|
+
while @index < @input.length && /[\d#{@decimal_separator}]/.match?(@input[@index])
|
69
|
+
@index += 1
|
70
|
+
end
|
71
|
+
result = @input[start_index...@index].gsub(@decimal_separator, '.').to_f
|
72
|
+
end
|
73
|
+
result
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "chronic"
|
2
|
+
|
3
|
+
module Inputomatic
|
4
|
+
class DateTime < ActiveRecord::Type::Value
|
5
|
+
def initialize(*args, format: :long_ordinal, **kwargs)
|
6
|
+
super *args, **kwargs
|
7
|
+
@format = format
|
8
|
+
end
|
9
|
+
|
10
|
+
def cast_value(value)
|
11
|
+
value.is_a?(String) ? Chronic.parse(value) : value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/inputomatic/version.rb
CHANGED
data/lib/inputomatic.rb
CHANGED
@@ -1,95 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "inputomatic/version"
|
4
|
-
require "chronic"
|
5
4
|
|
6
5
|
module Inputomatic
|
7
6
|
class Error < StandardError; end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@decimal_separator = decimal_separator
|
13
|
-
@index = 0
|
14
|
-
end
|
15
|
-
|
16
|
-
def parse
|
17
|
-
result = expression
|
18
|
-
if @index < @input.length
|
19
|
-
raise "Unexpected character: #{@input[@index]}"
|
20
|
-
end
|
21
|
-
result
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def expression
|
27
|
-
result = term
|
28
|
-
while @index < @input.length
|
29
|
-
case @input[@index]
|
30
|
-
when '+'
|
31
|
-
@index += 1
|
32
|
-
result += term
|
33
|
-
when '-'
|
34
|
-
@index += 1
|
35
|
-
result -= term
|
36
|
-
else
|
37
|
-
break
|
38
|
-
end
|
39
|
-
end
|
40
|
-
result
|
41
|
-
end
|
42
|
-
|
43
|
-
def term
|
44
|
-
result = factor
|
45
|
-
while @index < @input.length
|
46
|
-
case @input[@index]
|
47
|
-
when '*'
|
48
|
-
@index += 1
|
49
|
-
result *= factor
|
50
|
-
when '/'
|
51
|
-
@index += 1
|
52
|
-
result /= factor
|
53
|
-
else
|
54
|
-
break
|
55
|
-
end
|
56
|
-
end
|
57
|
-
result
|
58
|
-
end
|
59
|
-
|
60
|
-
def factor
|
61
|
-
if @input[@index] == '('
|
62
|
-
@index += 1
|
63
|
-
result = expression
|
64
|
-
if @input[@index] != ')'
|
65
|
-
raise "Expected ')'"
|
66
|
-
end
|
67
|
-
@index += 1
|
68
|
-
else
|
69
|
-
start_index = @index
|
70
|
-
while @index < @input.length && /[\d#{@decimal_separator}]/.match?(@input[@index])
|
71
|
-
@index += 1
|
72
|
-
end
|
73
|
-
result = @input[start_index...@index].gsub(@decimal_separator, '.').to_f
|
74
|
-
end
|
75
|
-
result
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
class DateTime < ActiveRecord::Type::Value
|
80
|
-
def initialize(*args, format: :long_ordinal, **kwargs)
|
81
|
-
super *args, **kwargs
|
82
|
-
@format = format
|
83
|
-
end
|
84
|
-
|
85
|
-
def cast_value(value)
|
86
|
-
value.is_a?(String) ? Chronic.parse(value) : value
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
class Number < ActiveRecord::Type::Value
|
91
|
-
def cast_value(value)
|
92
|
-
value.is_a?(String) ? ArithmeticInterpreter.new(value).parse : value
|
93
|
-
end
|
94
|
-
end
|
8
|
+
autoload :ArithmeticInterpreter, "inputomatic/arithmetic_interpreter"
|
9
|
+
autoload :DateTime, "inputomatic/date_time"
|
10
|
+
autoload :Number, "inputomatic/number"
|
95
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inputomatic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Gessler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chronic
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: Make text boxes in your web apps handle human inputs like '1+2' or 'next
|
28
42
|
tuesday'
|
29
43
|
email:
|
@@ -37,10 +51,14 @@ files:
|
|
37
51
|
- CHANGELOG.md
|
38
52
|
- CODE_OF_CONDUCT.md
|
39
53
|
- Gemfile
|
54
|
+
- Gemfile.lock
|
40
55
|
- LICENSE.txt
|
41
56
|
- README.md
|
42
57
|
- Rakefile
|
43
58
|
- lib/inputomatic.rb
|
59
|
+
- lib/inputomatic/arithmetic_interpreter.rb
|
60
|
+
- lib/inputomatic/date_time.rb
|
61
|
+
- lib/inputomatic/number.rb
|
44
62
|
- lib/inputomatic/version.rb
|
45
63
|
- sig/inputomatic.rbs
|
46
64
|
homepage: https://github.com/rocketshipio/inputomatic
|