say_it_with_graphs 0.1.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 (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +9 -0
  5. data/Gemfile +4 -0
  6. data/Guardfile +50 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +31 -0
  9. data/Rakefile +16 -0
  10. data/bin/say-it-with-graphs +11 -0
  11. data/lib/say_it_with_graphs/brush.rb +34 -0
  12. data/lib/say_it_with_graphs/characters/a.rb +26 -0
  13. data/lib/say_it_with_graphs/characters/bang.rb +41 -0
  14. data/lib/say_it_with_graphs/characters/e.rb +36 -0
  15. data/lib/say_it_with_graphs/characters/g.rb +33 -0
  16. data/lib/say_it_with_graphs/characters/h.rb +34 -0
  17. data/lib/say_it_with_graphs/characters/i.rb +20 -0
  18. data/lib/say_it_with_graphs/characters/l.rb +25 -0
  19. data/lib/say_it_with_graphs/characters/lt.rb +28 -0
  20. data/lib/say_it_with_graphs/characters/m.rb +30 -0
  21. data/lib/say_it_with_graphs/characters/o.rb +34 -0
  22. data/lib/say_it_with_graphs/characters/p.rb +32 -0
  23. data/lib/say_it_with_graphs/characters/r.rb +40 -0
  24. data/lib/say_it_with_graphs/characters/s.rb +33 -0
  25. data/lib/say_it_with_graphs/characters/space.rb +17 -0
  26. data/lib/say_it_with_graphs/characters/three.rb +37 -0
  27. data/lib/say_it_with_graphs/characters/v.rb +18 -0
  28. data/lib/say_it_with_graphs/client.rb +22 -0
  29. data/lib/say_it_with_graphs/frame.rb +18 -0
  30. data/lib/say_it_with_graphs/framer.rb +40 -0
  31. data/lib/say_it_with_graphs/graph_controls.rb +17 -0
  32. data/lib/say_it_with_graphs/line.rb +18 -0
  33. data/lib/say_it_with_graphs/version.rb +3 -0
  34. data/lib/say_it_with_graphs.rb +12 -0
  35. data/say_it_with_graphs.gemspec +28 -0
  36. data/spec/lib/say_it_with_graphs/brush_spec.rb +27 -0
  37. data/spec/lib/say_it_with_graphs/client_spec.rb +46 -0
  38. data/spec/lib/say_it_with_graphs/frame_spec.rb +36 -0
  39. data/spec/lib/say_it_with_graphs/framer_spec.rb +44 -0
  40. data/spec/lib/say_it_with_graphs/graph_controls_spec.rb +31 -0
  41. data/spec/lib/say_it_with_graphs/line_spec.rb +29 -0
  42. data/spec/spec_helper.rb +90 -0
  43. metadata +178 -0
@@ -0,0 +1,37 @@
1
+ module SayItWithGraphs
2
+ module Characters
3
+ class Three
4
+ include SayItWithGraphs::GraphControls
5
+
6
+ def define
7
+ '3'
8
+ end
9
+
10
+ def draw
11
+ a = rnd_line
12
+ b = rnd_line
13
+ c = rnd_line
14
+ d = rnd_line
15
+ frame do |f|
16
+ f.line[a].at 100
17
+ f.line[b].at 50
18
+ f.line[d].at 0
19
+ end
20
+ frame do |f|
21
+ f.line[a].at 100
22
+ f.line[b].at 50
23
+ f.line[c].at 50
24
+ f.line[d].at 0
25
+ end
26
+ frame do |f|
27
+ f.line[a].at 84
28
+ f.line[a].at 67
29
+ f.line[b].at 67
30
+ f.line[c].at 34
31
+ f.line[c].at 17
32
+ f.line[d].at 17
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,18 @@
1
+ module SayItWithGraphs
2
+ module Characters
3
+ class V
4
+ include SayItWithGraphs::GraphControls
5
+
6
+ def define
7
+ 'v'
8
+ end
9
+
10
+ def draw
11
+ a = rnd_line
12
+ frame { |f| f.line[a].at 100 }
13
+ frame { |f| f.line[a].at 0 }
14
+ frame { |f| f.line[a].at 100 }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ require 'httparty'
2
+
3
+ module SayItWithGraphs
4
+ class Client
5
+ include HTTParty
6
+ base_uri 'https://metrics-api.librato.com'
7
+
8
+ # debug_output $stdout
9
+
10
+ def self.submit value: value, source: source, name: 'say-it-with-graphs'
11
+ auth = { username: ENV['LIBRATO_USER'], password: ENV['LIBRATO_TOKEN'] }
12
+ metric = {
13
+ gauges: [{
14
+ name: name,
15
+ value: value,
16
+ source: source
17
+ }]
18
+ }
19
+ self.post('/v1/metrics', basic_auth: auth, headers: {'Content-Type' => 'application/json'}, body: metric.to_json)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ module SayItWithGraphs
2
+ class Frame
3
+ def initialize
4
+ @lines = []
5
+ end
6
+
7
+ def line
8
+ line = Line.new 0, 0
9
+ @lines << line
10
+ line
11
+ end
12
+ alias_method :lines, :line
13
+
14
+ def complete
15
+ @lines.freeze
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,40 @@
1
+ module SayItWithGraphs
2
+ class Framer
3
+
4
+ def initialize()
5
+ @characters = []
6
+ @mapping = {}
7
+ end
8
+
9
+ def frames(sentence)
10
+ @characters = sentence.split ''
11
+ load_mapping!
12
+ @characters.collect do |char|
13
+ character = char.downcase
14
+ validate! character
15
+ klass_for(character:character).new.draw
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def load_mapping!
22
+ SayItWithGraphs::Characters.constants.each do |const|
23
+ klass = eval("SayItWithGraphs::Characters::#{const}")
24
+ @mapping[klass.new.define.downcase] = klass
25
+ end
26
+ end
27
+
28
+ def validate!(character)
29
+ fail 'Not supported character!' unless valid? character
30
+ end
31
+
32
+ def valid?(character)
33
+ @mapping.has_key? character.downcase
34
+ end
35
+
36
+ def klass_for(character: char)
37
+ @mapping[character]
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ module SayItWithGraphs
2
+ module GraphControls
3
+ def initialize
4
+ @frames = []
5
+ end
6
+
7
+ def frame
8
+ frame = Frame.new
9
+ yield frame
10
+ @frames << frame
11
+ end
12
+
13
+ def rnd_line
14
+ SecureRandom.hex[0..5]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module SayItWithGraphs
2
+ class Line
3
+ attr_accessor :position
4
+ attr_reader :line_number
5
+
6
+ alias_method :at, :position=
7
+
8
+ def initialize(position = 0, line_number = 1)
9
+ @position = position
10
+ @line_number = line_number
11
+ end
12
+
13
+ def [](key)
14
+ @line_number = key
15
+ self
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module SayItWithGraphs
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,12 @@
1
+ require "say_it_with_graphs/version"
2
+ require "say_it_with_graphs/line"
3
+ require "say_it_with_graphs/frame"
4
+ require "say_it_with_graphs/graph_controls"
5
+ require "say_it_with_graphs/framer"
6
+ require "say_it_with_graphs/brush"
7
+ require "say_it_with_graphs/client"
8
+
9
+ Dir[File.join(__dir__, 'say_it_with_graphs', 'characters', '*.rb')].each {|file| require file}
10
+
11
+ module SayItWithGraphs
12
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'say_it_with_graphs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "say_it_with_graphs"
8
+ spec.version = SayItWithGraphs::VERSION
9
+ spec.authors = ["Ole Michaelis"]
10
+ spec.email = ["Ole.Michaelis@googlemail.com"]
11
+ spec.summary = %q{Make more of your graphs. Write with them!}
12
+ spec.description = %q{say-it-with-graphs let you actually write into a place where usually the computer tells you something.}
13
+ spec.homepage = "https://github.com/nesQuick/say-it-with-graphs"
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_dependency "httparty", "~> 0.13"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.2"
26
+ spec.add_development_dependency "guard", "~> 2.12"
27
+ spec.add_development_dependency "guard-rspec", "~> 4.5"
28
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'say_it_with_graphs/brush'
3
+ require 'say_it_with_graphs/client'
4
+
5
+ RSpec.describe SayItWithGraphs::Brush do
6
+
7
+ it { should respond_to :paint! }
8
+
9
+ before :each do
10
+ allow(subject).to receive(:sleep)
11
+ allow(subject).to receive(:p)
12
+ allow(subject).to receive(:rand).and_return(37)
13
+
14
+ allow(subject).to receive(:countdown)
15
+ end
16
+
17
+ let(:line) { double('line', position: 5, line_number: 10) }
18
+ let(:frame) { double('frame', complete: [line, line]) }
19
+ let(:frames) { [frame, [frame, frame]] }
20
+
21
+ describe '#paint!' do
22
+ it 'should send the lines to the client' do
23
+ expect(SayItWithGraphs::Client).to receive(:submit).with(value: 5, source: 'source-no-10', name: 'say-it-with-graphs-37').exactly(6).times
24
+ subject.paint! frames
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+ require 'say_it_with_graphs/client'
3
+
4
+ RSpec.describe SayItWithGraphs::Client do
5
+
6
+ subject { SayItWithGraphs::Client }
7
+
8
+ it { should respond_to :submit }
9
+
10
+ describe '.submit' do
11
+
12
+ let(:user) { 'some_user' }
13
+ let(:token) { 'some_token' }
14
+
15
+ let(:value) { 4 }
16
+ let(:source) { 'some_source' }
17
+
18
+ before :each do
19
+ ENV['LIBRATO_USER'] = user
20
+ ENV['LIBRATO_TOKEN'] = token
21
+ end
22
+
23
+ after :each do
24
+ ENV.delete 'LIBRATO_USER'
25
+ ENV.delete 'LIBRATO_TOKEN'
26
+ end
27
+
28
+ it 'should send metric to librato' do
29
+ expected_metric = {
30
+ gauges: [{
31
+ name: 'say-it-with-graphs',
32
+ value: value,
33
+ source: source
34
+ }]
35
+ }
36
+ expected_options = {
37
+ basic_auth: { username: user, password: token },
38
+ headers: {'Content-Type' => 'application/json'},
39
+ body: expected_metric.to_json
40
+ }
41
+ allow(subject).to receive(:post).with '/v1/metrics', expected_options
42
+
43
+ subject.submit value: value, source: source
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'say_it_with_graphs/frame'
3
+ require 'say_it_with_graphs/line'
4
+
5
+ RSpec.describe SayItWithGraphs::Frame do
6
+
7
+ it { should respond_to :line }
8
+ it { should respond_to :lines }
9
+
10
+ describe '#line' do
11
+ it 'should add the line to the frame' do
12
+ line = subject.line
13
+ expect(subject.complete).to include line
14
+ end
15
+ it 'should return a line' do
16
+ expect(subject.line).to be_a SayItWithGraphs::Line
17
+ end
18
+ it 'should return a line with default parameters' do
19
+ line = subject.line
20
+ expect(line.position).to be 0
21
+ expect(line.line_number).to be 0
22
+ end
23
+ end
24
+
25
+ describe '#complete' do
26
+ it 'should return all lines in frame' do
27
+ lines = 3.times { subject.line }
28
+ expect(subject.complete.length).to be 3
29
+ end
30
+ it 'should freeze the frame' do
31
+ subject.complete
32
+ expect{subject.line}.to raise_error RuntimeError
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'say_it_with_graphs/framer'
3
+ require 'say_it_with_graphs/graph_controls'
4
+ require 'say_it_with_graphs/characters/i'
5
+
6
+ RSpec.describe SayItWithGraphs::Framer do
7
+
8
+ it { should respond_to :frames }
9
+
10
+ let(:valid_phrase) { 'Hi' }
11
+ let(:invalid_phrase) { 'fününü' }
12
+
13
+ let(:character) { double(:draw) }
14
+
15
+ describe '#frames' do
16
+
17
+ before :each do
18
+ allow(SayItWithGraphs::Characters).to receive :constants
19
+ allow(character).to receive :draw
20
+ allow(subject).to receive :load_mapping!
21
+ allow(subject).to receive :validate!
22
+ allow(subject).to receive :valid?
23
+ allow(subject).to receive(:klass_for).and_return(double('character', new: character))
24
+ end
25
+
26
+ it 'should load the character to class mapping' do
27
+ expect(subject).to receive(:load_mapping!)
28
+ subject.frames valid_phrase
29
+ end
30
+
31
+ it 'should validate the characters' do
32
+ expect(subject).to receive(:validate!)
33
+ subject.frames invalid_phrase
34
+ end
35
+
36
+ it 'should return the frames for all characters' do
37
+ frame = double 'frame'
38
+ expect(character).to receive(:draw).and_return(frame)
39
+ expect(subject).to receive(:klass_for).and_return(double(new: character))
40
+ expect(subject.frames('i')).to eq [frame]
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+ require 'say_it_with_graphs/graph_controls'
3
+ require 'say_it_with_graphs/frame'
4
+
5
+ RSpec.describe SayItWithGraphs::GraphControls do
6
+
7
+ subject { (Class.new { include SayItWithGraphs::GraphControls }).new }
8
+
9
+ describe '#frame' do
10
+ it 'should yield the frame' do
11
+ frame = double 'frame'
12
+ allow(SayItWithGraphs::Frame).to receive(:new).and_return(frame)
13
+ expect { |b| subject.frame(&b) }.to yield_with_args(frame)
14
+ end
15
+
16
+ it 'should return all frame' do
17
+ frame1 = double 'frame'
18
+ frame2 = double 'frame'
19
+ allow(SayItWithGraphs::Frame).to receive(:new).and_return(frame1, frame2)
20
+ subject.frame {|f|}
21
+ expect(subject.frame {|f|}.length).to be 2
22
+ end
23
+ end
24
+
25
+ describe '#rnd_line' do
26
+ it 'should return random 6 character string to be used as line number' do
27
+ allow(SecureRandom).to receive(:hex).and_return('ba11ade')
28
+ expect(subject.rnd_line).to eq 'ba11ad'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'say_it_with_graphs/line'
3
+
4
+ RSpec.describe SayItWithGraphs::Line do
5
+
6
+ it { should respond_to :position }
7
+ it { should respond_to :line_number }
8
+ it { should respond_to :at }
9
+ it { should respond_to :[] }
10
+
11
+ describe '#initialize' do
12
+ it 'should default position to 0' do
13
+ expect(subject.position).to be 0
14
+ end
15
+ it 'should default line_number to 1' do
16
+ expect(subject.line_number).to be 1
17
+ end
18
+ end
19
+
20
+ describe '#[]' do
21
+ it 'should set the line number' do
22
+ expect(subject[2].line_number).to be 2
23
+ end
24
+ it 'should return itself' do
25
+ expect(subject[2]).to be subject
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,90 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is
54
+ # recommended. For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
+ config.disable_monkey_patching!
59
+
60
+ # This setting enables warnings. It's recommended, but in some cases may
61
+ # be too noisy due to issues in dependencies.
62
+ config.warnings = true
63
+
64
+ # Many RSpec users commonly either run the entire suite or an individual
65
+ # file, and it's useful to allow more verbose output when running an
66
+ # individual spec file.
67
+ if config.files_to_run.one?
68
+ # Use the documentation formatter for detailed output,
69
+ # unless a formatter has already been configured
70
+ # (e.g. via a command-line flag).
71
+ config.default_formatter = 'doc'
72
+ end
73
+
74
+ # Print the 10 slowest examples and example groups at the
75
+ # end of the spec run, to help surface which specs are running
76
+ # particularly slow.
77
+ config.profile_examples = 10
78
+
79
+ # Run specs in random order to surface order dependencies. If you find an
80
+ # order dependency and want to debug it, you can fix the order by providing
81
+ # the seed, which is printed after each run.
82
+ # --seed 1234
83
+ config.order = :random
84
+
85
+ # Seed global randomization in this process using the `--seed` CLI option.
86
+ # Setting this allows you to use `--seed` to deterministically reproduce
87
+ # test failures related to randomization by passing the same `--seed` value
88
+ # as the one that triggered the failure.
89
+ Kernel.srand config.seed
90
+ end