flex-station-data 1.0.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6814ca0e722e1da44873ec3cd5571864984f028be6bb098a548dc6b5a21af430
4
- data.tar.gz: cf535779a83284369d3a406590edd9a055e53cbc24fdcb49384f8445e829f170
3
+ metadata.gz: 1763fb10b625dcca4d933df8282802bc385298724270981ce178cd8bc8ff61f5
4
+ data.tar.gz: 27a12f5bbe2ecedc562b8c710b2211a74ab02c7b5fb4e02a9c7be3017df647bd
5
5
  SHA512:
6
- metadata.gz: 1ca3cbaa108a9bc868da418ad3c8393508b3ebe8e20db5a1a16427e5426981c07f3232329c3469f61cb2694feb08c8ded37225ed47af7dc0544b8c65941c6a68
7
- data.tar.gz: dc49217f185e779075f9f11aa7f2ec85cf958d18644383fdb01ea7827cdce64ab5c5aead16ee3c4148b82a9377de2ef71eaf47497e61e6b9323ff2a20a7b29e4
6
+ metadata.gz: e4a73af64d380f23083a029a87592074f99fdc88b83235111815687915423fccd05949a8354d13ed6ad546f60f22aa96a1cd68771ab564e1930889c9cd0c0c9c
7
+ data.tar.gz: c508621a8a1b89770dac4fdf2b5ab2bb897020f4c25128b3b721433a667a21acc24750627a5acefc48a09900ba13282808e396310e0dfb36c1a090e962ba500c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.0.1
2
+
3
+ * Miscellaneous refactoring.
4
+
1
5
  # 1.0.0
2
6
 
3
7
  * Removed option for sample data report and verbose linear regression report.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- flex-station-data (1.0.0)
4
+ flex-station-data (1.0.1)
5
5
  activesupport
6
6
  linefit
7
7
 
data/bin/flex-station CHANGED
@@ -1,16 +1,37 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "pathname"
4
+ require "flex_station_data/concerns/callable"
4
5
 
5
- case command = ARGV.first
6
- when "sample-data"
7
- system(Pathname(__dir__).join("flex-station-sample-data").to_path, *ARGV.drop(1))
8
- when "linear-regression"
9
- system(Pathname(__dir__).join("flex-station-linear-regression").to_path, *ARGV.drop(1))
10
- when nil
11
- $stderr.puts "USAGE: flex-station <command>"
12
- exit(1)
13
- else
14
- $stderr.puts "Unrecognised command: #{command}"
15
- exit(1)
6
+ class App
7
+ include FlexStationData::Concerns::Callable[:run]
8
+
9
+ attr_reader :command, :args
10
+
11
+ def initialize(command = "help", *args)
12
+ @command = command
13
+ @args = args
14
+ end
15
+
16
+ def dir_path
17
+ Pathname(__dir__)
18
+ end
19
+
20
+ def linear_regression_path
21
+ dir_path.join("flex-station-linear-regression")
22
+ end
23
+
24
+ def run
25
+ case command
26
+ when "linear-regression"
27
+ exec(linear_regression_path.to_path, *args)
28
+ when "help", "--help"
29
+ puts "USAGE: flex-station <command>"
30
+ else
31
+ $stderr.puts "Unrecognised command: #{command}"
32
+ exit(1)
33
+ end
34
+ end
16
35
  end
36
+
37
+ App.run(*ARGV)
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require "flex_station_data/concerns/callable"
3
4
  require "flex_station_data/services/load_plates"
4
5
  require "flex_station_data/presenters/plates_hash"
5
6
 
6
7
  module FlexStationData
7
8
  class LinearRegressionApp
8
- include Concerns::Service
9
+ include Concerns::Callable[:run]
9
10
 
10
11
  OPTION_RE = /\A--(\w+(?:-\w+)*)(?:=(.*))?\z/.freeze
11
12
 
@@ -78,7 +79,7 @@ module FlexStationData
78
79
  [ hash.keys, *hash.values.transpose ]
79
80
  end
80
81
 
81
- def call
82
+ def run
82
83
  CSV do |out|
83
84
  csv.each do |row|
84
85
  out << row
@@ -88,4 +89,4 @@ module FlexStationData
88
89
  end
89
90
  end
90
91
 
91
- FlexStationData::LinearRegressionApp.call(*ARGV)
92
+ FlexStationData::LinearRegressionApp.run(*ARGV)
@@ -0,0 +1,33 @@
1
+ module FlexStationData
2
+ module Concerns
3
+ module Callable
4
+ class << self
5
+ def [](verb)
6
+ @@__callable_modules[verb] ||= Module.new.tap { |mod| __make_callable(mod, verb) }
7
+ end
8
+
9
+ private
10
+
11
+ def __make_callable(mod, verb)
12
+ class_methods = Module.new do
13
+ define_method verb do |*args, &block|
14
+ new(*args).send(verb, &block)
15
+ end
16
+
17
+ define_method :to_proc do
18
+ Proc.new(&method(verb))
19
+ end
20
+ end
21
+
22
+ mod.singleton_class.define_method :included do |base|
23
+ base.extend class_methods
24
+ end
25
+ end
26
+ end
27
+
28
+ __make_callable(self, :call)
29
+
30
+ @@__callable_modules = { call: self }
31
+ end
32
+ end
33
+ end
@@ -1,23 +1,7 @@
1
- require "active_support/concern"
1
+ require_relative "callable"
2
2
 
3
3
  module FlexStationData
4
4
  module Concerns
5
- module Presenter
6
- extend ActiveSupport::Concern
7
-
8
- def to_proc
9
- Proc.new(&method(:present))
10
- end
11
-
12
- class_methods do
13
- def present(*args, &block)
14
- new(*args).present(&block)
15
- end
16
-
17
- def to_proc
18
- Proc.new(&method(:present))
19
- end
20
- end
21
- end
5
+ Presenter = Callable[:present]
22
6
  end
23
7
  end
@@ -1,23 +1,7 @@
1
- require "active_support/concern"
1
+ require_relative "callable"
2
2
 
3
3
  module FlexStationData
4
4
  module Concerns
5
- module Service
6
- extend ActiveSupport::Concern
7
-
8
- def to_proc
9
- Proc.new(&method(:call))
10
- end
11
-
12
- class_methods do
13
- def call(*args, &block)
14
- new(*args).call(&block)
15
- end
16
-
17
- def to_proc
18
- Proc.new(&method(:call))
19
- end
20
- end
21
- end
5
+ Service = Callable
22
6
  end
23
7
  end
@@ -1,3 +1,3 @@
1
1
  module FlexStationData
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flex-station-data
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Carney
@@ -117,6 +117,7 @@ files:
117
117
  - bin/flex-station-linear-regression
118
118
  - flex-station-data.gemspec
119
119
  - lib/flex_station_data.rb
120
+ - lib/flex_station_data/concerns/callable.rb
120
121
  - lib/flex_station_data/concerns/presenter.rb
121
122
  - lib/flex_station_data/concerns/service.rb
122
123
  - lib/flex_station_data/default_sample_map.rb