seamusabshere-conversions 1.4.0 → 1.4.1

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.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ documentation
2
+ *.gem
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2008 Manfred Stienstra, Fingertips <manfred@fngtps.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,44 @@
1
+ = Conversions
2
+
3
+ Unit conversion:
4
+
5
+ 1.miles.to(:kilometres) #=> 1.609344
6
+ 1.pounds.to(:kilograms) #=> 0.453592
7
+ 1.pounds.to(:kilograms, 2) #=> 0.45
8
+
9
+ Or, more explicitly,
10
+
11
+ 1.convert(:miles, :kilometres) #=> 1.609344
12
+ 1.convert(:pounds, :kilograms) #=> 0.453592
13
+ 1.convert(:pounds, :kilograms, :scale => 2) #=> 0.45
14
+
15
+ You can register your own conversions:
16
+
17
+ Conversions.register(:miles, :nautical_miles, 0.868976242)
18
+ 1.miles.to(:nautical_miles) #=> 0.868976242
19
+
20
+ It also adds a class method to ActiveRecord::Base that allows you to define conversion methods for attributes:
21
+
22
+ class Car < ActiveRecord::Base
23
+ conversion_accessor :weight, :internal => :kilograms, :external => :pounds
24
+ end
25
+
26
+ car = Car.new(:weight => 1500)
27
+ car.weight_in_pounds #=> 3306.93393
28
+ car.weight_in_pounds = 3306 #=> 3306
29
+
30
+ == Installation
31
+
32
+ === As a gem
33
+
34
+ Configure the gem in environment.rb:
35
+
36
+ config.gem 'Fingertips-conversions', :lib => 'conversions', :source => 'http://gems.github.com'
37
+
38
+ Install them using Rails' rake task:
39
+
40
+ $ rake gems:install
41
+
42
+ === In your vendor directory:
43
+
44
+ script/install plugin git://github.com/Fingertips/conversions.git
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ require 'rake/testtask'
2
+ require 'rake/rdoctask'
3
+
4
+ desc 'Default: run unit tests.'
5
+ task :default => :test
6
+
7
+ desc 'Test the conversions plugin.'
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << 'lib'
10
+ t.pattern = 'test/**/*_test.rb'
11
+ t.verbose = true
12
+ end
13
+
14
+ namespace :rdoc do
15
+ desc 'Generate documentation for conversions plugin.'
16
+ Rake::RDocTask.new(:generate) do |rdoc|
17
+ rdoc.rdoc_dir = 'documentation'
18
+ rdoc.title = 'Conversions'
19
+ rdoc.options << '--line-numbers' << '--inline-source' << '--charset' << 'utf-8'
20
+ rdoc.rdoc_files.include('README', 'lib/**/*.rb')
21
+ end
22
+ end
23
+
24
+ begin
25
+ require 'jeweler'
26
+ Jeweler::Tasks.new do |spec|
27
+ spec.name = "conversions"
28
+
29
+ spec.author = "Manfred Stienstra"
30
+ spec.email = "manfred@fngtps.com"
31
+
32
+ spec.description = <<-EOF
33
+ A Ruby on Rails plugin that adds conversion capabilities to numeric objects"
34
+ EOF
35
+ spec.summary = <<-EOF
36
+ A Ruby on Rails plugin that adds conversion capabilities to numeric objects"
37
+ EOF
38
+ spec.homepage = "http://github.com/Fingertips/conversions/tree/master"
39
+ end
40
+ rescue LoadError
41
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
42
+ end
data/TODO ADDED
File without changes
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :major: 1
3
2
  :minor: 4
4
- :patch: 0
3
+ :patch: 1
4
+ :major: 1
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{conversions}
8
+ s.version = "1.4.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Manfred Stienstra"]
12
+ s.date = %q{2009-08-21}
13
+ s.description = %q{ A Ruby on Rails plugin that adds conversion capabilities to numeric objects"
14
+ }
15
+ s.email = %q{manfred@fngtps.com}
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README"
19
+ ]
20
+ s.files = [
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README",
24
+ "Rakefile",
25
+ "TODO",
26
+ "VERSION.yml",
27
+ "conversions.gemspec",
28
+ "init.rb",
29
+ "lib/conversions.rb",
30
+ "lib/conversions/active_record_accessors.rb",
31
+ "lib/conversions/defaults.rb",
32
+ "lib/conversions/unit.rb",
33
+ "rails/init.rb",
34
+ "test/accessor_test.rb",
35
+ "test/conversions_test.rb",
36
+ "test/ext_test.rb",
37
+ "test/test_helper.rb",
38
+ "test/unit_test.rb"
39
+ ]
40
+ s.homepage = %q{http://github.com/Fingertips/conversions/tree/master}
41
+ s.rdoc_options = ["--charset=UTF-8"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.3.5}
44
+ s.summary = %q{A Ruby on Rails plugin that adds conversion capabilities to numeric objects"}
45
+ s.test_files = [
46
+ "test/accessor_test.rb",
47
+ "test/conversions_test.rb",
48
+ "test/ext_test.rb",
49
+ "test/test_helper.rb",
50
+ "test/unit_test.rb"
51
+ ]
52
+
53
+ if s.respond_to? :specification_version then
54
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
55
+ s.specification_version = 3
56
+
57
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
58
+ else
59
+ end
60
+ else
61
+ end
62
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'conversions'
@@ -9,6 +9,14 @@ module Conversions
9
9
  @value = value
10
10
  @from = from
11
11
  end
12
+
13
+ def to_i
14
+ @value.to_i
15
+ end
16
+
17
+ def to_f
18
+ @value.to_f
19
+ end
12
20
 
13
21
  # Convert to a certain other unit.
14
22
  #
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'init')
data/test/unit_test.rb CHANGED
@@ -48,6 +48,12 @@ class UnitTest < Test::Unit::TestCase
48
48
  end
49
49
  end
50
50
 
51
+ def test_to_f_and_to_i
52
+ amount = Conversions::Unit.new(10.5, :miles)
53
+ assert_equal 10, amount.to_i
54
+ assert_equal 10.5, amount.to_f
55
+ end
56
+
51
57
  def test_register
52
58
  Conversions.register(:dollars, :cents, 100.0)
53
59
  assert_in_delta 0.01, Conversions::Unit.exchange_rate(:cents, :dollars), DELTA
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seamusabshere-conversions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manfred Stienstra
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-16 00:00:00 -07:00
12
+ date: 2009-08-21 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -19,25 +19,33 @@ executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files: []
23
-
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README
24
25
  files:
26
+ - .gitignore
27
+ - LICENSE
28
+ - README
29
+ - Rakefile
30
+ - TODO
25
31
  - VERSION.yml
26
- - lib/conversions
32
+ - conversions.gemspec
33
+ - init.rb
34
+ - lib/conversions.rb
27
35
  - lib/conversions/active_record_accessors.rb
28
36
  - lib/conversions/defaults.rb
29
37
  - lib/conversions/unit.rb
30
- - lib/conversions.rb
38
+ - rails/init.rb
31
39
  - test/accessor_test.rb
32
40
  - test/conversions_test.rb
33
41
  - test/ext_test.rb
34
42
  - test/test_helper.rb
35
43
  - test/unit_test.rb
36
- has_rdoc: true
44
+ has_rdoc: false
37
45
  homepage: http://github.com/Fingertips/conversions/tree/master
46
+ licenses:
38
47
  post_install_message:
39
48
  rdoc_options:
40
- - --inline-source
41
49
  - --charset=UTF-8
42
50
  require_paths:
43
51
  - lib
@@ -56,9 +64,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
64
  requirements: []
57
65
 
58
66
  rubyforge_project:
59
- rubygems_version: 1.2.0
67
+ rubygems_version: 1.3.5
60
68
  signing_key:
61
- specification_version: 2
69
+ specification_version: 3
62
70
  summary: A Ruby on Rails plugin that adds conversion capabilities to numeric objects"
63
- test_files: []
64
-
71
+ test_files:
72
+ - test/accessor_test.rb
73
+ - test/conversions_test.rb
74
+ - test/ext_test.rb
75
+ - test/test_helper.rb
76
+ - test/unit_test.rb