alchemist 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/lib/alchemist.rb +32 -9
  3. metadata +5 -3
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ PKG_FILES = %w(Rakefile) +
6
6
 
7
7
  gem_spec = Gem::Specification.new do |gem_spec|
8
8
  gem_spec.name = 'alchemist'
9
- gem_spec.version = '0.0.7'
9
+ gem_spec.version = '0.0.8'
10
10
  gem_spec.summary = 'Conversions... like you\'ve never seen them before!'
11
11
  gem_spec.description = 'Conversions... like you\'ve never seen them before!!'
12
12
  gem_spec.email = 'matt@toastyapps.com'
data/lib/alchemist.rb CHANGED
@@ -83,8 +83,8 @@ module Alchemist
83
83
  :circle_of_the_earth => 40075016.686, :equator => 40075016.686, :circles_of_the_earth => 40075016.686, :equators => 40075016.686,
84
84
  :siriometer => 1.494838e+17, :siriometers => 1.494838e+17,
85
85
  :football_field => 91.0, :football_fields => 91.0,
86
- :length_of_a_double_decker_bus => 8.4, :height_of_a_double_decker_bus => 4.4
87
-
86
+ :length_of_a_double_decker_bus => 8.4, :height_of_a_double_decker_bus => 4.4,
87
+ :smoot => 1.7018, :smoots => 1.7018
88
88
  },
89
89
  :dose_equivalent => {
90
90
  :sievert => 1.0, :sieverts => 1.0, :Si => 1.0,
@@ -291,7 +291,7 @@ module Alchemist
291
291
  :sydharb => 5.0e+11, :sydharbs => 5.0e+11
292
292
  }
293
293
  }
294
- @@british_standard_unit_prefixes = {
294
+ @@unit_prefixes = {
295
295
  :googol => 1e+100,
296
296
  :yotta => 1e+24, :Y => 1e+24,
297
297
  :zetta => 1e+21, :Z => 1e+21,
@@ -312,15 +312,26 @@ module Alchemist
312
312
  :femto => 1e-15, :f => 1e-15,
313
313
  :atto => 1e-18, :a => 1e-18,
314
314
  :zepto => 1e-21, :z => 1e-21,
315
- :yocto => 1e-24, :y => 1e-24
315
+ :yocto => 1e-24, :y => 1e-24,
316
+
317
+ # binary prefixes
318
+
319
+ :kibi => 2.0**10.0, :Ki => 2.0**10.0,
320
+ :mebi => 2.0**20.0, :Mi => 2.0**20.0,
321
+ :gibi => 2.0**30.0, :Gi => 2.0**30.0,
322
+ :tebi => 2.0**40.0, :Ti => 2.0**40.0,
323
+ :pebi => 2.0**50.0, :Pi => 2.0**50.0,
324
+ :exbi => 2.0**60.0, :Ei => 2.0**60.0,
325
+ :zebi => 2.0**70.0, :Zi => 2.0**70.0,
326
+ :yobi => 2.0**80.0, :Yi => 2.0**80.0
316
327
  }
317
328
 
318
329
  def from(unit_name)
319
330
  send(unit_name)
320
331
  end
321
332
 
322
- def self.british_standard_unit_prefixes
323
- @@british_standard_unit_prefixes
333
+ def self.unit_prefixes
334
+ @@unit_prefixes
324
335
  end
325
336
 
326
337
  def self.conversion_table
@@ -394,10 +405,20 @@ module Alchemist
394
405
  NumericConversion.new self, unit_name, exponent
395
406
  end
396
407
 
408
+ def self.register(type, names, value)
409
+ names = [names] unless names.is_a?(Array)
410
+ value = value.is_a?(NumericConversion) ? value.base(type) : value
411
+ names.each do |name|
412
+ Conversions[name] ||= []
413
+ Conversions[name] << type
414
+ Alchemist.conversion_table[type][name] = value
415
+ end
416
+ end
417
+
397
418
  def self.parse_prefix(unit)
398
- @@british_standard_unit_prefixes.each do |prefix, value|
419
+ @@unit_prefixes.each do |prefix, value|
399
420
  if unit.to_s =~ /^#{prefix}.+/ && @@si_units.include?(unit.to_s.gsub(/^#{prefix}/,''))
400
- if !(Conversions[ unit.to_s.gsub(/^#{prefix}/,'').to_sym ] & [ :information_storage ]).empty? && !@use_si && value >= 1000.0
421
+ if !(Conversions[ unit.to_s.gsub(/^#{prefix}/,'').to_sym ] & [ :information_storage ]).empty? && !@use_si && value >= 1000.0 && value.to_i & -value.to_i != value
401
422
  value = 2 ** (10 * (Math.log(value) / Math.log(10)) / 3)
402
423
  end
403
424
  return [value, unit.to_s.gsub(/^#{prefix}/,'').to_sym]
@@ -416,4 +437,6 @@ end
416
437
 
417
438
  class Numeric
418
439
  include Alchemist
419
- end
440
+ end
441
+
442
+ puts 5.angstroms.inspect
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alchemist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Mongeau
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-10 00:00:00 -05:00
12
+ date: 2009-11-11 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -26,6 +26,8 @@ files:
26
26
  - lib/alchemist.rb
27
27
  has_rdoc: true
28
28
  homepage: http://github.com/toastyapps/alchemist
29
+ licenses: []
30
+
29
31
  post_install_message:
30
32
  rdoc_options: []
31
33
 
@@ -46,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
48
  requirements: []
47
49
 
48
50
  rubyforge_project:
49
- rubygems_version: 1.3.1
51
+ rubygems_version: 1.3.5
50
52
  signing_key:
51
53
  specification_version: 3
52
54
  summary: Conversions... like you've never seen them before!