sy 2.0.5 → 2.0.6

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
  SHA1:
3
- metadata.gz: 666dbe08efdd97d407e931045726b9668f5bf3c2
4
- data.tar.gz: aa13e418672f7223bcdb63683eb42c511974b2f2
3
+ metadata.gz: 4b93dcc72a697919f9557a9349a50d1e87612c68
4
+ data.tar.gz: 6bda09a872a0c2f0db3d4d2e9c908622c5344934
5
5
  SHA512:
6
- metadata.gz: deb58fde2b519570d6fc891a9e259aeafca50d541e6807c26075e4e1cd7415355378070baa05f231d449a36252d8cbd286120fdd37245fde87b79501a2e19dd2
7
- data.tar.gz: 695f6feedb083dd82b35ebc7720a6aa89586dba97bee1ce4ff0a28a93fcf012e1957f0e7a8cabd618e328b89226f272eb5673dec1770c0ffcc211c1f847ad420
6
+ metadata.gz: e891618f42a48a1a9c9891736990c0a77ced68ce06299c06efa9a9dab7b5bbd11bf8f4de01655726afc07b0fe904e7c482568fc0de1820ca8f4c12efc547c86d
7
+ data.tar.gz: ad9d0857a802dbae9307e38de6417756351dee3b1e5ec0cb7dd7bd61dd895aebc75e8a42f68878865709c883151611ca14f1afb86c07591699170dd8dd44d1e9
@@ -17,20 +17,27 @@ module SY::AbsoluteMagnitude
17
17
  # and :amount named argument, where amount must be nonnegative.
18
18
  #
19
19
  def initialize( of: nil, amount: nil )
20
+ puts "Constructing AbsoluteMagnitude of #{of}, amount: #{amount}" if SY::DEBUG
20
21
  fail ArgumentError, "Quantity (:of) argument missing!" if of.nil?
21
22
  @quantity = of
22
23
  @amount = case amount
23
- when Numeric then amount
24
- when nil then 1
24
+ when Numeric then
25
+ puts "This amount is a Numeric, using it directly" if SY::DEBUG
26
+ amount
27
+ when nil then
28
+ puts "This amount is 'nil', using 1 instead" if SY::DEBUG
29
+ 1
25
30
  else
26
31
  begin
32
+ puts "Amount #{amount} will be reframed to #{@quantity}" if SY::DEBUG
27
33
  amount.( @quantity ).amount
28
34
  rescue NameError, NoMethodError
35
+ puts "fail, amount #{amount} will be used directly" if SY::DEBUG
29
36
  amount
30
37
  end
31
38
  end
32
- fail SY::MagnitudeError, "Unsigned magnitudes may not have negative " +
33
- "amount!" if @amount < 0
39
+ fail SY::MagnitudeError, "Attempt to construct an unsigned magnitude " +
40
+ "(SY::AbsoluteMagnitude) with a negative amount." if @amount < 0
34
41
  end
35
42
 
36
43
  # For absolute magnitudes, #+ method always returns a result framed in
data/lib/sy/magnitude.rb CHANGED
@@ -251,7 +251,8 @@ module SY::Magnitude
251
251
 
252
252
  #
253
253
  def to_s( unit=quantity.units.first || quantity.standard_unit,
254
- number_format=default_amount_format )
254
+ number_format=default_amount_format ) # FIXME: TUTO JE TO KUREVSTVO TU SA TA JEDNOTKA KONSTRUUJE
255
+ puts "#to_s called on a magnitude of quantity #{quantity}" if SY::DEBUG
255
256
  # step 1: produce pairs [number, unit_presentation],
256
257
  # where unit_presentation is an array of triples
257
258
  # [prefix, unit, exponent], which together give the
@@ -419,6 +420,7 @@ module SY::Magnitude
419
420
  # Inspect string of the magnitude
420
421
  #
421
422
  def inspect
423
+ puts "inspect called on a magnitude of quantity #{quantity}" if SY::DEBUG
422
424
  "#<#{çς}: #{self} >"
423
425
  end
424
426
 
data/lib/sy/quantity.rb CHANGED
@@ -237,7 +237,9 @@ class SY::Quantity
237
237
  # Constructs a new absolute magnitude of this quantity.
238
238
  #
239
239
  def magnitude amount
240
- Magnitude().new of: self, amount: amount
240
+ puts "Constructing #{self}#magnitude with amount #{amount}." if SY::DEBUG
241
+ Magnitude().new( of: self, amount: amount )
242
+ .tap { puts "#{self}#magnitude constructed!" if SY::DEBUG }
241
243
  end
242
244
 
243
245
  # Constructs a new unit of this quantity.
@@ -364,8 +366,9 @@ class SY::Quantity
364
366
  # Main parametrized (ie. quantity-specific) module for magnitudes.
365
367
  #
366
368
  def MagnitudeModule
369
+ puts "#{self}#MagnitudeModule called" if SY::DEBUG
367
370
  @MagnitudeModule ||= if absolute? then
368
- Module.new { include ::SY::Magnitude }
371
+ Module.new { include SY::Magnitude }
369
372
  else
370
373
  absolute.MagnitudeModule
371
374
  end
@@ -374,8 +377,10 @@ class SY::Quantity
374
377
  # Parametrized magnitude class.
375
378
  #
376
379
  def Magnitude
380
+ puts "#{self}#Magnitude called" if SY::DEBUG
377
381
  @Magnitude or
378
- ( mmod = MagnitudeModule()
382
+ ( puts "Constructing #{self}@Magnitude parametrized class" if SY::DEBUG
383
+ mmod = MagnitudeModule()
379
384
  mixin = relative? ? SY::SignedMagnitude : SY::AbsoluteMagnitude
380
385
  qnt_ɴ_λ = -> { name ? "#{name}@%s" : "#<Quantity:#{object_id}@%s>" }
381
386
 
@@ -398,24 +403,27 @@ class SY::Quantity
398
403
  # Parametrized unit class.
399
404
  #
400
405
  def Unit
401
- @Unit ||= if relative? then absolute.Unit else
402
- qnt = self
403
- ɴλ = -> { name ? "#{name}@%s" : "#<Quantity:#{object_id}@%s>" }
404
-
405
- Class.new Magnitude() do # Unit class.
406
- include SY::Unit
407
-
408
- singleton_class.class_exec do
409
- define_method :standard do |**nn| # Customized #standard.
410
- @standard ||= new **nn.update( of: qnt )
411
- end
406
+ puts "#{self}#Unit called" if SY::DEBUG
407
+ @Unit ||= ( puts "Constructing #{self}@Unit parametrized class" if SY::DEBUG
408
+ if relative? then absolute.Unit else
409
+ qnt = self
410
+ ɴλ = -> { name ? "#{name}@%s" : "#<Quantity:#{object_id}@%s>" }
412
411
 
413
- define_method :to_s do # Customized #to_s. (Same consideration
414
- ɴλ.call % "Unit" # as for @Magnitude applies.)
412
+ Class.new Magnitude() do # Unit class.
413
+ include SY::Unit
414
+
415
+ singleton_class.class_exec do
416
+ define_method :standard do |**nn| # Customized #standard.
417
+ puts "parametrized #{qnt}@Unit#standard called" if SY::DEBUG
418
+ @standard ||= new **nn.update( of: qnt )
419
+ end
420
+
421
+ define_method :to_s do # Customized #to_s. (Same consideration
422
+ ɴλ.call % "Unit" # as for @Magnitude applies.)
423
+ end
415
424
  end
416
425
  end
417
- end
418
- end
426
+ end )
419
427
  end
420
428
 
421
429
  private
@@ -6,15 +6,22 @@ module SY::SignedMagnitude
6
6
  # :amount argument. Amount is allowed to be negative.
7
7
  #
8
8
  def initialize( of: nil, amount: nil )
9
+ puts "Constructing AbsoluteMagnitude of #{of}, amount: #{amount}" if SY::DEBUG
9
10
  fail ArgumentError, "Quantity (:of) argument missing!" if of.nil?
10
11
  @quantity = of
11
12
  @amount = case amount
12
- when Numeric then amount
13
- when nil then 1
13
+ when Numeric then
14
+ puts "This amount is a Numeric, using it directly" if SY::DEBUG
15
+ amount
16
+ when nil then
17
+ puts "This amount is 'nil', using 1 instead" if SY::DEBUG
18
+ 1
14
19
  else
15
20
  begin
21
+ puts "Amount #{amount} will be reframed to #{@quantity}" if SY::DEBUG
16
22
  amount.( @quantity ).amount
17
23
  rescue NameError, NoMethodError
24
+ puts "fail, amount #{amount} will be used directly" if SY::DEBUG
18
25
  amount
19
26
  end
20
27
  end
data/lib/sy/unit.rb CHANGED
@@ -21,14 +21,31 @@ module SY::Unit
21
21
  # abbreviations and unit names regardless of capitalization
22
22
  #
23
23
  def self.instance arg
24
+ puts "SY::Unit module #instance method activated" if SY::DEBUG
24
25
  begin
25
26
  super # let's first try the original method
27
+ .tap { puts "original #instance method provided by NameMagic succeeded" if SY::DEBUG }
26
28
  rescue NameError # if we fail...
29
+ puts "original #instance method provided by NameMagic returned NameError" if SY::DEBUG
27
30
  begin # second in order, let's try whether it's an abbreviation
28
- super instances.find { |inst|
29
- inst.abbreviation.to_s == arg.to_s if inst.abbreviation
31
+ puts "trying whether the argument is an abbreviation" if SY::DEBUG
32
+ rslt = instances.find { |unit_inst|
33
+ if unit_inst.abbreviation then
34
+ if unit_inst.abbreviation.to_s == arg.to_s then
35
+ puts "For supplied argument #{arg} (#{arg.class}), it seems that " +
36
+ "unit #{unit_inst} of quantity #{unit_inst.quantity} has abbreviation " +
37
+ "#{unit_inst.abbreviation} matching it." if SY::DEBUG
38
+ true
39
+ else
40
+ false
41
+ end
42
+ end
43
+ # inst.abbreviation.to_s == arg.to_s if inst.abbreviation
30
44
  }
45
+ fail NameError if rslt.nil? # if nothing found, super need not be called
46
+ super rslt
31
47
  rescue NameError, TypeError
48
+ puts "failed, we'll now try to upcase the argument in case of all-downcase argument" if SY::DEBUG
32
49
  begin # finally, let's try upcase if we have all-downcase arg
33
50
  super arg.to_s.upcase
34
51
  rescue NameError # if not, tough luck
data/lib/sy/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module SY
2
- VERSION = "2.0.5"
2
+ VERSION = "2.0.6"
3
3
  DEBUG = false # debug mode switch - sometimes there are lines like
4
4
  # puts "something" if SY::DEBUG
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - boris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-22 00:00:00.000000000 Z
11
+ date: 2013-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport