vv 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aafa1b0844a59d8158b402e9e7e51c325dae6082d79bc508949b33aeb7987b0f
4
- data.tar.gz: 35f64d79aab93c8b38943fbe758968e3b4e4e9e8c8b05ed59b162bf11417ecb1
3
+ metadata.gz: 3c8c547349232035004a745cf52e55bd36defde893a895fb1cd92227d96959b0
4
+ data.tar.gz: 7e2126cd0d4b9e25372567a17bff5a64f9ca635bad9dc1bab9f59dcdac10cc7e
5
5
  SHA512:
6
- metadata.gz: cf4313d3280e92c44c191670fb17433ef984e73cc15f857c62af00cc3acda49a033310897fa96f484528de043dac1661b4da1d585287331996cf07eb3f5f2f86
7
- data.tar.gz: f2beba8849297663d145f907affda65f8823f4b8389284d205af6288468d26ac9b76df0b6dc8fe7ccbdaf9c941bf2c87cf1993b7795b7814e48137dc5ae0b42a
6
+ metadata.gz: e74e8862eec31bca21f58fa8f3edeed18dad800b45d5cc8fb66da56bc0c24f5d923ba7283c7785091d2c05a25ff07edaf1b57a51a8d36ba2d78910254ddc2aea
7
+ data.tar.gz: 0c9110bf3f7246f722cd6e65c7d1f461d821afb64a3364585a116c7d437689dc78b55378771de511887cc3248992e95be88ffaa7f68ab9ddc2578a4290275a9d
@@ -0,0 +1,32 @@
1
+ module VV
2
+ module ComplexMethods
3
+
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ def vv_included?
11
+ true
12
+ end
13
+
14
+ end
15
+
16
+ def to_d
17
+ self.non_imaginary!
18
+ self.real.to_f.to_d
19
+ end
20
+
21
+ def real_digits unsafe: false
22
+ self.non_imaginary! unless unsafe
23
+ self.real.to_d.to_digits
24
+ end
25
+
26
+ def non_imaginary!
27
+ message = "Complex number contains imaginary part."
28
+ fail message if imaginary?
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ module VV
2
+ module DecimalMethods
3
+
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ def vv_included?
11
+ true
12
+ end
13
+
14
+ end
15
+
16
+ def vv_json **kwargs
17
+ self.to_digits
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,69 @@
1
+ module VV
2
+ module NumericMethods
3
+
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ def vv_included?
11
+ true
12
+ end
13
+
14
+ end
15
+
16
+ def imaginary?
17
+ ! ( self.imaginary == 0 )
18
+ end
19
+
20
+ def real_digits
21
+ return real.to_digits if real.respond_to? :to_digits
22
+ real.to_s
23
+ end
24
+
25
+ def readable_number precision: 3, significant: false
26
+ message = "Cannot make imaginary number readable"
27
+ fail message if imaginary?
28
+
29
+ _int_digits,
30
+ _remaining_digits = self.real_digits.split String.period
31
+
32
+ _int_digits = \
33
+ _int_digits.after String.dash, safe: false
34
+
35
+ if _int_digits.size > 4
36
+ # TODO: This type of pattern comes up all the time with
37
+ # strings. Figure out a way of abstracting it.
38
+ offset = ( _int_digits.size ) % 3
39
+ required = ( _int_digits.size - 1 ) / 3
40
+
41
+ index = required * 3 + ( offset % -3 )
42
+ while index > 0
43
+ _int_digits.insert(index, String.comma)
44
+ index -= 3
45
+ end
46
+ end
47
+
48
+ response = \
49
+ real.negative? ? String.dash : String.empty_string
50
+
51
+ response += _int_digits
52
+ return response unless _remaining_digits
53
+ response += String.period
54
+
55
+ last_digit = significant ? -1 : ( precision )
56
+ if significant || precision >= _remaining_digits.size
57
+ dec_portion = _remaining_digits
58
+ else
59
+ dec_portion = \
60
+ ( _remaining_digits[0..last_digit].to_f / 10 )
61
+ .round.to_s
62
+ end
63
+
64
+ response + dec_portion
65
+ end
66
+ alias_method :readable, :readable_number
67
+
68
+ end
69
+ end
@@ -61,6 +61,10 @@ module VV
61
61
  "="
62
62
  end
63
63
 
64
+ def comma
65
+ ","
66
+ end
67
+
64
68
  def period
65
69
  "."
66
70
  end
@@ -111,6 +115,16 @@ module VV
111
115
  self.end_with?(*args)
112
116
  end
113
117
 
118
+ def shift
119
+ self.slice!(0)
120
+ end
121
+ alias_method :shift!, :shift
122
+
123
+ def pop
124
+ self.slice!(-1)
125
+ end
126
+ alias_method :pop!, :pop
127
+
114
128
  def after(string, safe: true)
115
129
  if safe && ! self.starts_with?(string)
116
130
  message = "String does not start with #{string}"
@@ -65,6 +65,7 @@ module VV
65
65
  module_function :version
66
66
 
67
67
  def build( name: , argv: nil )
68
+ argv ||= []
68
69
  simple = %w[ simple force ].include? argv.first
69
70
  return build_simple name: name if simple
70
71
 
data/lib/vv/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module VV
2
- VERSION = '0.0.13'
2
+ VERSION = '0.0.14'
3
3
  end
data/lib/vv.rb CHANGED
@@ -49,6 +49,18 @@ class NilClass
49
49
  include VV::NilMethods
50
50
  end
51
51
 
52
+ class Numeric
53
+ include VV::NumericMethods
54
+ end
55
+
56
+ class BigDecimal
57
+ include VV::DecimalMethods
58
+ end
59
+
60
+ class Complex
61
+ include VV::ComplexMethods
62
+ end
63
+
52
64
  class Integer
53
65
  include VV::IntegerMethods
54
66
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Aysan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-25 00:00:00.000000000 Z
11
+ date: 2019-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -64,6 +64,8 @@ files:
64
64
  - lib/vv.rb
65
65
  - lib/vv/array_methods.rb
66
66
  - lib/vv/cli.rb
67
+ - lib/vv/complex_methods.rb
68
+ - lib/vv/decimal_methods.rb
67
69
  - lib/vv/false_methods.rb
68
70
  - lib/vv/file_methods.rb
69
71
  - lib/vv/float_methods.rb
@@ -71,6 +73,7 @@ files:
71
73
  - lib/vv/hash_methods.rb
72
74
  - lib/vv/integer_methods.rb
73
75
  - lib/vv/nil_methods.rb
76
+ - lib/vv/numeric_methods.rb
74
77
  - lib/vv/object_methods.rb
75
78
  - lib/vv/random_methods.rb
76
79
  - lib/vv/readline_methods.rb