vangogh 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 80adbf0ea988235079c45eadfedd8665363c1736
4
+ data.tar.gz: 58f370396da56f00f2f1c618831df14b6fbdd71c
5
+ SHA512:
6
+ metadata.gz: 9922f54a815b3a48f3a88a6c693e18eac872e3eacaaa37efb70148348fd075ea3843db64fad6339f2691a554ba817f7ea5aa8a541557937e1933614808153595
7
+ data.tar.gz: b77ca744bde7b0fba3f889f37441cdd3a31fbcaf05ccdea6fb49c7a5a856f759234616d61d3de0660f18d49297e5dd536ccfeea2e2cd2f63b702bdfa6e535f36
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vangogh.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Ben Balter
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Vangogh
2
+
3
+ A Ruby Gem for abstracting numbers
4
+
5
+ ## Usage
6
+
7
+ ```Ruby
8
+ # Abstract numbers
9
+ Vangogh.abstract 1234
10
+ => 1200
11
+
12
+ Vangogh.abstract 12345
13
+ => 12000
14
+
15
+ # Abstract and abbreviate
16
+ Vangogh.abbrevaite 1234
17
+ => "1.2k"
18
+
19
+ Vangogh.abbreviate 12345
20
+ => "12.3k"
21
+ ```
22
+
23
+ You can also extend the numbers themselves, if you prefer:
24
+
25
+ ```ruby
26
+ require 'vangogh/ext'
27
+
28
+ 1234.abstract
29
+ => 1200
30
+
31
+ 12345.abbreviate
32
+ "12.3k"
33
+ ```
34
+
35
+ Heck, you can even use it via command line:
36
+
37
+ ```
38
+ $ vangogh abstract 1234
39
+ 1200
40
+
41
+ $ vangogh abbreviate 12345
42
+ 12.3k
43
+ ``
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/benbalter/vangogh/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ require_relative './lib/vangogh'
4
+
5
+ desc "Run specs"
6
+ RSpec::Core::RakeTask.new do |t|
7
+ t.pattern = 'spec/**/*_spec.rb'
8
+ t.rspec_opts = ["--order", "rand", "--color"]
9
+ end
data/bin/vangogh ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative "../lib/vangogh"
3
+ require 'thor'
4
+
5
+ class VangoghCli < Thor
6
+ desc "abstract VALUE", "Abstract the given value (e.g., 1234 -> 1200)"
7
+ def abstract(value)
8
+ puts Vangogh.abstract(value.to_f)
9
+ end
10
+
11
+ desc "abbreviate VALUE", "Abbreviate the given value (e.g., 1234 -> 1.2k)"
12
+ def abbreviate(value)
13
+ puts Vangogh.abbreviate(value.to_f)
14
+ end
15
+ end
16
+
17
+ VangoghCli.start
data/lib/vangogh.rb ADDED
@@ -0,0 +1,15 @@
1
+ require_relative "vangogh/version"
2
+ require_relative "vangogh/number"
3
+ require 'si/minimal'
4
+
5
+ module Vangogh
6
+ class << self
7
+ def abstract(value)
8
+ Number.new(value).abstract
9
+ end
10
+
11
+ def abbreviate(value)
12
+ Number.new(value).abbreviate
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ class Numeric
2
+ def abstract
3
+ Vangogh.abstract(self)
4
+ end
5
+
6
+ def abbreviate
7
+ Vangogh.abbreviate(self)
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+ module Vangogh
2
+ class Number
3
+
4
+ attr_accessor :value
5
+
6
+ def initialize(value)
7
+ @value = value
8
+ end
9
+
10
+ def abstract
11
+ value.round(1 - abstracted_digits)
12
+ end
13
+
14
+ def abbreviate
15
+ SI.convert(abstract).sub(/0+([a-z])/i, "\\1").sub(/\.([a-z])/i, "\\1")
16
+ end
17
+
18
+ private
19
+
20
+ def digits
21
+ value.to_i.to_s.length
22
+ end
23
+
24
+ def abstracted_digits
25
+ if digits <= 4
26
+ 3
27
+ elsif digits <= 6
28
+ 4
29
+ elsif digits <= 7
30
+ 5
31
+ elsif digits <= 8
32
+ 6
33
+ elsif digits > 8
34
+ 7
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Vangogh
2
+ VERSION = "0.0.1"
3
+ end
data/script/bootstrap ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ bundle install
data/script/cibuild ADDED
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+
3
+ set -e
4
+
5
+ bundle exec rake spec
6
+ gem build vangogh.gemspec
data/script/console ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ bundle exec pry -r ./lib/vangogh.rb
data/script/release ADDED
@@ -0,0 +1,38 @@
1
+ #!/bin/sh
2
+ # Tag and push a release.
3
+
4
+ set -e
5
+
6
+ # Make sure we're in the project root.
7
+
8
+ cd $(dirname "$0")/..
9
+
10
+ # Build a new gem archive.
11
+
12
+ rm -rf vangogh-*.gem
13
+ gem build -q vangogh.gemspec
14
+
15
+ # Make sure we're on the master branch.
16
+
17
+ (git branch | grep -q '* master') || {
18
+ echo "Only release from the master branch."
19
+ exit 1
20
+ }
21
+
22
+ # Figure out what version we're releasing.
23
+
24
+ tag=v`ls vangogh-*.gem | sed 's/^vangogh-\(.*\)\.gem$/\1/'`
25
+
26
+ # Make sure we haven't released this version before.
27
+
28
+ git fetch -t origin
29
+
30
+ (git tag -l | grep -q "$tag") && {
31
+ echo "Whoops, there's already a '${tag}' tag."
32
+ exit 1
33
+ }
34
+
35
+ # Tag it and bag it.
36
+
37
+ gem push vangogh-*.gem && git tag "$tag" &&
38
+ git push origin master && git push origin "$tag"
data/spec/helper.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/setup"
2
+ require_relative "../lib/vangogh"
@@ -0,0 +1,11 @@
1
+ require_relative "helper"
2
+
3
+ describe "Vangogh::Bin" do
4
+ it "abstracts values" do
5
+ expect(`bundle exec vangogh abstract 1234`.strip).to eql("1200")
6
+ end
7
+
8
+ it "abbreviates values" do
9
+ expect(`bundle exec vangogh abbreviate 1234`.strip).to eql("1.2k")
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ require_relative "helper"
2
+ require "vangogh/ext"
3
+
4
+ describe "Vangogh::Ext" do
5
+ it "extends integers" do
6
+ expect(1234.abstract).to eql(1200)
7
+ expect(1234.abbreviate).to eql("1.2k")
8
+ end
9
+
10
+ it "extends floats" do
11
+ expect(1234.56.abstract).to eql(1200)
12
+ expect(1234.56.abbreviate).to eql("1.2k")
13
+ end
14
+ end
@@ -0,0 +1,62 @@
1
+ require_relative "helper"
2
+
3
+ describe Vangogh::Number do
4
+
5
+ subject { Vangogh::Number.new(1234) }
6
+
7
+ it "stores the value" do
8
+ expect(subject.value).to eql(1234)
9
+ end
10
+
11
+ it "knows the number of digits" do
12
+ expect(subject.send(:digits)).to eql(4)
13
+ end
14
+
15
+ it "handles numbers less than 10" do
16
+ number = Vangogh::Number.new(1)
17
+ expect(number.abstract).to eql(0)
18
+ expect(number.abbreviate).to eql("0")
19
+ end
20
+
21
+ it "handles numbers less than 100" do
22
+ number = Vangogh::Number.new(12)
23
+ expect(number.abstract).to eql(0)
24
+ expect(number.abbreviate).to eql("0")
25
+ end
26
+
27
+ it "handles numbers less than 1000" do
28
+ number = Vangogh::Number.new(123)
29
+ expect(number.abstract).to eql(100)
30
+ expect(number.abbreviate).to eql("100")
31
+ end
32
+
33
+ it "handles numbers less than 10,000" do
34
+ number = Vangogh::Number.new(1234)
35
+ expect(number.abstract).to eql(1200)
36
+ expect(number.abbreviate).to eql("1.2k")
37
+ end
38
+
39
+ it "handles numbers less than 100,000" do
40
+ number = Vangogh::Number.new(12345)
41
+ expect(number.abstract).to eql(12000)
42
+ expect(number.abbreviate).to eql("12k")
43
+ end
44
+
45
+ it "handles numbers less than 1,000,000" do
46
+ number = Vangogh::Number.new(123456)
47
+ expect(number.abstract).to eql(123000)
48
+ expect(number.abbreviate).to eql("123k")
49
+ end
50
+
51
+ it "handles numbers less than 1,000,000" do
52
+ number = Vangogh::Number.new(1234567)
53
+ expect(number.abstract).to eql(1230000)
54
+ expect(number.abbreviate).to eql("1.23M")
55
+ end
56
+
57
+ it "handles numbers greater than 1,000,000" do
58
+ number = Vangogh::Number.new(12345678)
59
+ expect(number.abstract).to eql(12300000)
60
+ expect(number.abbreviate).to eql("12.3M")
61
+ end
62
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'helper'
2
+
3
+ describe Vangogh do
4
+ it "abstracts numbers" do
5
+ expect(subject.abstract(1234)).to eql(1200)
6
+ end
7
+
8
+ it "abbreviates numbers" do
9
+ expect(subject.abbreviate(1234)).to eql("1.2k")
10
+ end
11
+ end
data/vangogh.gemspec ADDED
@@ -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 'vangogh/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vangogh"
8
+ spec.version = Vangogh::VERSION
9
+ spec.authors = ["Ben Balter"]
10
+ spec.email = ["ben.balter@github.com"]
11
+ spec.summary = "A Ruby Gem for abstracting numbers"
12
+ spec.homepage = "https://github.com/benbalter/vangogh"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "si"
21
+ spec.add_dependency "thor"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "pry"
26
+ spec.add_development_dependency "rspec"
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vangogh
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ben Balter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: si
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
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: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - ben.balter@github.com
100
+ executables:
101
+ - vangogh
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/vangogh
111
+ - lib/vangogh.rb
112
+ - lib/vangogh/ext.rb
113
+ - lib/vangogh/number.rb
114
+ - lib/vangogh/version.rb
115
+ - script/bootstrap
116
+ - script/cibuild
117
+ - script/console
118
+ - script/release
119
+ - spec/helper.rb
120
+ - spec/vangogh_bin_spec.rb
121
+ - spec/vangogh_ext_spec.rb
122
+ - spec/vangogh_number_spec.rb
123
+ - spec/vangogh_spec.rb
124
+ - vangogh.gemspec
125
+ homepage: https://github.com/benbalter/vangogh
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.2.3
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: A Ruby Gem for abstracting numbers
149
+ test_files:
150
+ - spec/helper.rb
151
+ - spec/vangogh_bin_spec.rb
152
+ - spec/vangogh_ext_spec.rb
153
+ - spec/vangogh_number_spec.rb
154
+ - spec/vangogh_spec.rb