gum 0.2.1 → 0.3.0

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.
Files changed (65) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE.txt +1 -1
  3. data/README.md +435 -16
  4. data/exe/gum +11 -0
  5. data/gum.gemspec +28 -32
  6. data/lib/gum/command.rb +159 -0
  7. data/lib/gum/commands/choose.rb +95 -0
  8. data/lib/gum/commands/confirm.rb +57 -0
  9. data/lib/gum/commands/file.rb +84 -0
  10. data/lib/gum/commands/filter.rb +119 -0
  11. data/lib/gum/commands/format.rb +74 -0
  12. data/lib/gum/commands/input.rb +68 -0
  13. data/lib/gum/commands/join.rb +41 -0
  14. data/lib/gum/commands/log.rb +98 -0
  15. data/lib/gum/commands/pager.rb +55 -0
  16. data/lib/gum/commands/spin.rb +167 -0
  17. data/lib/gum/commands/style.rb +93 -0
  18. data/lib/gum/commands/table.rb +93 -0
  19. data/lib/gum/commands/write.rb +84 -0
  20. data/lib/gum/upstream.rb +17 -0
  21. data/lib/gum/version.rb +5 -1
  22. data/lib/gum.rb +170 -10
  23. data/sig/gum/command.rbs +23 -0
  24. data/sig/gum/commands/choose.rbs +42 -0
  25. data/sig/gum/commands/confirm.rbs +30 -0
  26. data/sig/gum/commands/file.rbs +38 -0
  27. data/sig/gum/commands/filter.rbs +48 -0
  28. data/sig/gum/commands/format.rbs +47 -0
  29. data/sig/gum/commands/input.rbs +32 -0
  30. data/sig/gum/commands/join.rbs +24 -0
  31. data/sig/gum/commands/log.rbs +56 -0
  32. data/sig/gum/commands/pager.rbs +28 -0
  33. data/sig/gum/commands/spin.rbs +55 -0
  34. data/sig/gum/commands/style.rbs +44 -0
  35. data/sig/gum/commands/table.rbs +35 -0
  36. data/sig/gum/commands/write.rbs +35 -0
  37. data/sig/gum/upstream.rbs +9 -0
  38. data/sig/gum/version.rbs +5 -0
  39. data/sig/gum.rbs +79 -0
  40. metadata +49 -145
  41. data/.gitignore +0 -9
  42. data/.rspec +0 -2
  43. data/.travis.yml +0 -5
  44. data/Gemfile +0 -4
  45. data/Rakefile +0 -6
  46. data/bin/console +0 -14
  47. data/bin/setup +0 -8
  48. data/gum-0.2.0.gem +0 -0
  49. data/lib/gum/factory.rb +0 -33
  50. data/lib/gum/filter.rb +0 -28
  51. data/lib/gum/filters/exists.rb +0 -25
  52. data/lib/gum/filters/fuzzy.rb +0 -11
  53. data/lib/gum/filters/geo/bbox.rb +0 -70
  54. data/lib/gum/filters/geo/distance.rb +0 -26
  55. data/lib/gum/filters/geo/range.rb +0 -33
  56. data/lib/gum/filters/geo.rb +0 -10
  57. data/lib/gum/filters/prefix.rb +0 -15
  58. data/lib/gum/filters/range.rb +0 -22
  59. data/lib/gum/filters/regexp.rb +0 -11
  60. data/lib/gum/filters/term.rb +0 -15
  61. data/lib/gum/filters/terms.rb +0 -11
  62. data/lib/gum/filters/wildcard.rb +0 -15
  63. data/lib/gum/filters.rb +0 -35
  64. data/lib/gum/order.rb +0 -18
  65. data/lib/gum/search.rb +0 -83
@@ -0,0 +1,35 @@
1
+ # Generated from lib/gum/commands/table.rb with RBS::Inline
2
+
3
+ module Gum
4
+ # Display and select from tabular data
5
+ #
6
+ # @example From array of arrays
7
+ # selection = Gum.table([["Alice", 30], ["Bob", 25]], columns: %w[Name Age])
8
+ #
9
+ # @example From CSV string
10
+ # Gum.table(File.read("data.csv"))
11
+ #
12
+ # @example With custom separator
13
+ # Gum.table(data, separator: "\t")
14
+ class Table
15
+ # Display tabular data and optionally allow row selection
16
+ #
17
+ # @rbs data: String | Array[Array[untyped]] -- CSV string or array of row arrays
18
+ # @rbs columns: Array[String]? -- column headers (required when data is array)
19
+ # @rbs separator: String? -- column separator (default: ",")
20
+ # @rbs widths: Array[Integer]? -- column widths
21
+ # @rbs height: Integer? -- table height in rows
22
+ # @rbs print: bool? -- print table without selection (non-interactive)
23
+ # @rbs border: Symbol | String | nil -- border style (:rounded, :thick, :normal, :hidden, :double, :none)
24
+ # @rbs border_foreground: String | Integer | nil -- border color
25
+ # @rbs border_background: String | Integer | nil -- border background color
26
+ # @rbs cell_foreground: String | Integer | nil -- cell text color
27
+ # @rbs cell_background: String | Integer | nil -- cell background color
28
+ # @rbs header_foreground: String | Integer | nil -- header text color
29
+ # @rbs header_background: String | Integer | nil -- header background color
30
+ # @rbs selected_foreground: String | Integer | nil -- selected row text color
31
+ # @rbs selected_background: String | Integer | nil -- selected row background color
32
+ # @rbs return: String? -- selected row data, or nil if cancelled
33
+ def self.call: (String | Array[Array[untyped]] data, ?columns: Array[String]?, ?separator: String?, ?widths: Array[Integer]?, ?height: Integer?, ?print: bool?, ?border: Symbol | String | nil, ?border_foreground: String | Integer | nil, ?border_background: String | Integer | nil, ?cell_foreground: String | Integer | nil, ?cell_background: String | Integer | nil, ?header_foreground: String | Integer | nil, ?header_background: String | Integer | nil, ?selected_foreground: String | Integer | nil, ?selected_background: String | Integer | nil) -> String?
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ # Generated from lib/gum/commands/write.rb with RBS::Inline
2
+
3
+ module Gum
4
+ # Prompt for multi-line text input
5
+ #
6
+ # @example Basic multi-line input
7
+ # description = Gum.write(placeholder: "Enter description...")
8
+ #
9
+ # @example With dimensions
10
+ # notes = Gum.write(width: 80, height: 10, header: "Notes")
11
+ class Write
12
+ # Prompt for multi-line text input (Ctrl+D to submit)
13
+ #
14
+ # @rbs placeholder: String? -- placeholder text shown when empty
15
+ # @rbs prompt: String? -- prompt string shown at the start of each line
16
+ # @rbs value: String? -- initial value for the text area
17
+ # @rbs char_limit: Integer? -- maximum number of characters allowed
18
+ # @rbs width: Integer? -- width of the text area
19
+ # @rbs height: Integer? -- height of the text area in lines
20
+ # @rbs header: String? -- header text displayed above the input
21
+ # @rbs show_cursor_line: bool? -- highlight the line with the cursor
22
+ # @rbs show_line_numbers: bool? -- display line numbers
23
+ # @rbs timeout: Integer? -- timeout in seconds (0 = no timeout)
24
+ # @rbs cursor: Hash[Symbol, untyped]? -- cursor style options
25
+ # @rbs cursor_line: Hash[Symbol, untyped]? -- cursor line highlight style
26
+ # @rbs placeholder_style: Hash[Symbol, untyped]? -- placeholder text style
27
+ # @rbs prompt_style: Hash[Symbol, untyped]? -- prompt text style
28
+ # @rbs end_of_buffer: Hash[Symbol, untyped]? -- end of buffer character style
29
+ # @rbs line_number: Hash[Symbol, untyped]? -- line number style
30
+ # @rbs header_style: Hash[Symbol, untyped]? -- header text style
31
+ # @rbs base: Hash[Symbol, untyped]? -- base text style
32
+ # @rbs return: String? -- the entered text, or nil if cancelled
33
+ def self.call: (?placeholder: String?, ?prompt: String?, ?value: String?, ?char_limit: Integer?, ?width: Integer?, ?height: Integer?, ?header: String?, ?show_cursor_line: bool?, ?show_line_numbers: bool?, ?timeout: Integer?, ?cursor: Hash[Symbol, untyped]?, ?cursor_line: Hash[Symbol, untyped]?, ?placeholder_style: Hash[Symbol, untyped]?, ?prompt_style: Hash[Symbol, untyped]?, ?end_of_buffer: Hash[Symbol, untyped]?, ?line_number: Hash[Symbol, untyped]?, ?header_style: Hash[Symbol, untyped]?, ?base: Hash[Symbol, untyped]?) -> String?
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+ # Generated from lib/gum/upstream.rb with RBS::Inline
2
+
3
+ module Gum
4
+ module Upstream
5
+ VERSION: ::String
6
+
7
+ NATIVE_PLATFORMS: untyped
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ # Generated from lib/gum/version.rb with RBS::Inline
2
+
3
+ module Gum
4
+ VERSION: ::String
5
+ end
data/sig/gum.rbs ADDED
@@ -0,0 +1,79 @@
1
+ # Generated from lib/gum.rb with RBS::Inline
2
+
3
+ module Gum
4
+ GEM_NAME: ::String
5
+
6
+ DEFAULT_DIR: untyped
7
+
8
+ class Error < StandardError
9
+ end
10
+
11
+ class ExecutableNotFoundException < Error
12
+ end
13
+
14
+ class UnsupportedPlatformException < Error
15
+ end
16
+
17
+ class DirectoryNotFoundException < Error
18
+ end
19
+
20
+ def self.execute: (*untyped args) -> untyped
21
+
22
+ def self.platform: () -> untyped
23
+
24
+ def self.version: () -> untyped
25
+
26
+ def self.executable: (?exe_path: untyped) -> untyped
27
+
28
+ # Prompt for single-line input
29
+ # @see Gum::Input#call
30
+ def self.input: (**untyped) -> untyped
31
+
32
+ # Prompt for multi-line text input
33
+ # @see Gum::Write#call
34
+ def self.write: (**untyped) -> untyped
35
+
36
+ # Choose from a list of options
37
+ # @see Gum::Choose#call
38
+ def self.choose: (untyped items, **untyped) -> untyped
39
+
40
+ # Filter items with fuzzy matching
41
+ # @see Gum::Filter#call
42
+ def self.filter: (untyped items, **untyped) -> untyped
43
+
44
+ # Prompt for confirmation
45
+ # @see Gum::Confirm#call
46
+ def self.confirm: (?untyped prompt, **untyped) -> untyped
47
+
48
+ # Pick a file from the filesystem
49
+ # @see Gum::FilePicker#call
50
+ def self.file: (?untyped path, **untyped) -> untyped
51
+
52
+ # Display content in a scrollable pager
53
+ # @see Gum::Pager#call
54
+ def self.pager: (untyped content, **untyped) -> untyped
55
+
56
+ # Display a spinner while running a command or block
57
+ # @see Gum::Spin#call
58
+ def self.spin: (?untyped title, **untyped) ?{ (?) -> untyped } -> untyped
59
+
60
+ # Apply styling to text
61
+ # @see Gum::Style#call
62
+ def self.style: (*untyped text, **untyped) -> untyped
63
+
64
+ # Join text blocks together
65
+ # @see Gum::Join#call
66
+ def self.join: (*untyped texts, **untyped) -> untyped
67
+
68
+ # Format text (markdown, code, template, emoji)
69
+ # @see Gum::Format#call
70
+ def self.format: (*untyped text, **untyped) -> untyped
71
+
72
+ # Display and select from tabular data
73
+ # @see Gum::Table#call
74
+ def self.table: (untyped data, **untyped) -> untyped
75
+
76
+ # Log a message
77
+ # @see Gum::Log#call
78
+ def self.log: (untyped message, **untyped) -> untyped
79
+ end
metadata CHANGED
@@ -1,162 +1,68 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Anton Sozontov
8
- autorequire:
7
+ - Marco Roth
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2016-11-24 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.13'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.13'
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: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.0'
55
- - !ruby/object:Gem::Dependency
56
- name: pry-byebug
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3.4'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '3.4'
69
- - !ruby/object:Gem::Dependency
70
- name: simplecov
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: activesupport
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '3.2'
90
- - - "<"
91
- - !ruby/object:Gem::Version
92
- version: '5.1'
93
- type: :runtime
94
- prerelease: false
95
- version_requirements: !ruby/object:Gem::Requirement
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- version: '3.2'
100
- - - "<"
101
- - !ruby/object:Gem::Version
102
- version: '5.1'
103
- - !ruby/object:Gem::Dependency
104
- name: chewy
105
- requirement: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - "~>"
108
- - !ruby/object:Gem::Version
109
- version: 0.8.4
110
- type: :runtime
111
- prerelease: false
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - "~>"
115
- - !ruby/object:Gem::Version
116
- version: 0.8.4
117
- description: Gum provides simple DSL for searching in your Elasticsearch
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Integrate Charm's gum with the RubyGems infrastructure.
118
13
  email:
119
- - a.sozontov@gmail.com
120
- executables: []
14
+ - marco.roth@intergga.ch
15
+ executables:
16
+ - gum
121
17
  extensions: []
122
18
  extra_rdoc_files: []
123
19
  files:
124
- - ".gitignore"
125
- - ".rspec"
126
- - ".travis.yml"
127
- - Gemfile
128
20
  - LICENSE.txt
129
21
  - README.md
130
- - Rakefile
131
- - bin/console
132
- - bin/setup
133
- - gum-0.2.0.gem
22
+ - exe/gum
134
23
  - gum.gemspec
135
24
  - lib/gum.rb
136
- - lib/gum/factory.rb
137
- - lib/gum/filter.rb
138
- - lib/gum/filters.rb
139
- - lib/gum/filters/exists.rb
140
- - lib/gum/filters/fuzzy.rb
141
- - lib/gum/filters/geo.rb
142
- - lib/gum/filters/geo/bbox.rb
143
- - lib/gum/filters/geo/distance.rb
144
- - lib/gum/filters/geo/range.rb
145
- - lib/gum/filters/prefix.rb
146
- - lib/gum/filters/range.rb
147
- - lib/gum/filters/regexp.rb
148
- - lib/gum/filters/term.rb
149
- - lib/gum/filters/terms.rb
150
- - lib/gum/filters/wildcard.rb
151
- - lib/gum/order.rb
152
- - lib/gum/search.rb
25
+ - lib/gum/command.rb
26
+ - lib/gum/commands/choose.rb
27
+ - lib/gum/commands/confirm.rb
28
+ - lib/gum/commands/file.rb
29
+ - lib/gum/commands/filter.rb
30
+ - lib/gum/commands/format.rb
31
+ - lib/gum/commands/input.rb
32
+ - lib/gum/commands/join.rb
33
+ - lib/gum/commands/log.rb
34
+ - lib/gum/commands/pager.rb
35
+ - lib/gum/commands/spin.rb
36
+ - lib/gum/commands/style.rb
37
+ - lib/gum/commands/table.rb
38
+ - lib/gum/commands/write.rb
39
+ - lib/gum/upstream.rb
153
40
  - lib/gum/version.rb
154
- homepage: https://github.com/qwiqer/gum
41
+ - sig/gum.rbs
42
+ - sig/gum/command.rbs
43
+ - sig/gum/commands/choose.rbs
44
+ - sig/gum/commands/confirm.rbs
45
+ - sig/gum/commands/file.rbs
46
+ - sig/gum/commands/filter.rbs
47
+ - sig/gum/commands/format.rbs
48
+ - sig/gum/commands/input.rbs
49
+ - sig/gum/commands/join.rbs
50
+ - sig/gum/commands/log.rbs
51
+ - sig/gum/commands/pager.rbs
52
+ - sig/gum/commands/spin.rbs
53
+ - sig/gum/commands/style.rbs
54
+ - sig/gum/commands/table.rbs
55
+ - sig/gum/commands/write.rbs
56
+ - sig/gum/upstream.rbs
57
+ - sig/gum/version.rbs
58
+ homepage: https://github.com/marcoroth/gum-ruby
155
59
  licenses:
156
60
  - MIT
157
61
  metadata:
158
- allowed_push_host: https://rubygems.org
159
- post_install_message:
62
+ homepage_uri: https://github.com/marcoroth/gum-ruby
63
+ source_code_uri: https://github.com/marcoroth/gum-ruby
64
+ changelog_uri: https://github.com/marcoroth/gum-ruby/releases
65
+ rubygems_mfa_required: 'true'
160
66
  rdoc_options: []
161
67
  require_paths:
162
68
  - lib
@@ -164,16 +70,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
70
  requirements:
165
71
  - - ">="
166
72
  - !ruby/object:Gem::Version
167
- version: '0'
73
+ version: 3.2.0
168
74
  required_rubygems_version: !ruby/object:Gem::Requirement
169
75
  requirements:
170
76
  - - ">="
171
77
  - !ruby/object:Gem::Version
172
78
  version: '0'
173
79
  requirements: []
174
- rubyforge_project:
175
- rubygems_version: 2.5.1
176
- signing_key:
80
+ rubygems_version: 3.6.9
177
81
  specification_version: 4
178
- summary: Search DSL on top of chewy gem
82
+ summary: Ruby wrapper for Charm's gum CLI tool.
179
83
  test_files: []
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.1
5
- before_install: gem install bundler -v 1.13.0
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in gum.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'gum'
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
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/gum-0.2.0.gem DELETED
Binary file
data/lib/gum/factory.rb DELETED
@@ -1,33 +0,0 @@
1
- module Gum
2
- class Factory
3
- def self.build(type, args)
4
- mapping = args_to_mapping(args)
5
- options = mapping.delete(:options)
6
- mapping.each do |param, field|
7
- yield new(type, param, field, options)
8
- end
9
- end
10
-
11
- def self.args_to_mapping(args)
12
- args.inject({}) do |mapping, arg|
13
- mapping.update normalize_mapping(arg)
14
- end
15
- end
16
-
17
- def self.normalize_mapping(mapping)
18
- case mapping
19
- when Hash
20
- mapping
21
- when Array
22
- mapping.zip(mapping).to_h
23
- else
24
- { mapping => mapping }
25
- end
26
- end
27
-
28
- def self.new(type, param, field, options)
29
- filter = type.is_a?(Class) ? type : Filters.const_get(type.to_s.camelize, false)
30
- filter.new param, field, options
31
- end
32
- end
33
- end
data/lib/gum/filter.rb DELETED
@@ -1,28 +0,0 @@
1
- module Gum
2
- class Filter
3
- attr_reader :param, :field, :options
4
-
5
- def initialize(param, field, options)
6
- @param = param
7
- @field = field
8
- @options = options || {}
9
- end
10
-
11
- def render(params)
12
- return if empty?(params)
13
- __render__ value_from(params)
14
- end
15
-
16
- def value_from(params)
17
- params[param].presence
18
- end
19
-
20
- def empty?(params)
21
- params[param].blank?
22
- end
23
-
24
- def __render__(value)
25
- raise NoMethodError
26
- end
27
- end
28
- end
@@ -1,25 +0,0 @@
1
- module Gum
2
- module Filters
3
- class Exists < Filter
4
- private
5
-
6
- FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE'].to_set
7
-
8
- def __render__(value)
9
- if value
10
- { exists: { field: field } }
11
- else
12
- { bool: { must_not: { exists: { field: field } } } }
13
- end
14
- end
15
-
16
- def value_from(params)
17
- !FALSE_VALUES.include?(super)
18
- end
19
-
20
- def empty?(value)
21
- value.nil? || value.try(:empty?)
22
- end
23
- end
24
- end
25
- end
@@ -1,11 +0,0 @@
1
- module Gum
2
- module Filters
3
- class Fuzzy < Filter
4
- private
5
-
6
- def __render__(value)
7
- { fuzzy: { field => { value: value }.merge(options) } }
8
- end
9
- end
10
- end
11
- end
@@ -1,70 +0,0 @@
1
- module Gum
2
- module Filters
3
- class Geo
4
- class Bbox < Filter
5
- private
6
-
7
- def __render__(value)
8
- {
9
- geo_bounding_box: {
10
- field => {
11
- top: value.top,
12
- left: value.left,
13
- bottom: value.bottom,
14
- right: value.right
15
- }
16
- }
17
- }
18
- end
19
-
20
- def parser
21
- @_parser ||= ParamParser.new(options[:pattern])
22
- end
23
-
24
- def value_from(params)
25
- parser.parse(super)
26
- end
27
-
28
- def empty?(params)
29
- super || parser.empty?(params[param])
30
- end
31
-
32
- class ParamParser
33
- attr_reader :top, :left, :bottom, :right
34
-
35
- def initialize(order)
36
- @order = order || 'top,left,bottom,right'
37
- @regexp = regexp
38
- end
39
-
40
- def empty?(value)
41
- !@regexp.match(value)
42
- end
43
-
44
- def parse(value)
45
- match_data = @regexp.match(value)
46
- return unless match_data
47
- @top = match_data[:top].to_f
48
- @left = match_data[:left].to_f
49
- @bottom = match_data[:bottom].to_f
50
- @right = match_data[:right].to_f
51
- self
52
- end
53
-
54
- private
55
-
56
- def number_pattern
57
- '-?\\d{,3}\\.?\\d{,16}'
58
- end
59
-
60
- def regexp
61
- order = @order.split(',').map do |param|
62
- "(?<#{param}>#{number_pattern})"
63
- end.join(',')
64
- /^#{order}$/
65
- end
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,26 +0,0 @@
1
- module Gum
2
- module Filters
3
- class Geo
4
- class Distance < Filter
5
- private
6
-
7
- def __render__(value)
8
- {
9
- geo_distance: {
10
- distance: value[:distance],
11
- field => value[:lat_lon]
12
- }
13
- }
14
- end
15
-
16
- def value_from(params)
17
- return nil unless params[:"#{param}"].present? && params[:"#{param}_distance"].present?
18
- {
19
- distance: params[:"#{param}_distance"],
20
- lat_lon: params[:"#{param}"]
21
- }
22
- end
23
- end
24
- end
25
- end
26
- end