artworker 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .DS_Store
2
+ *.log
3
+ *.sqlite3
4
+ *.gem
5
+ .rvmrc
6
+ .bundle
7
+ Gemfile.lock
8
+ pkg/*
9
+ spec/database.yml
10
+
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ #Artworker Changelog
2
+
3
+ ##0.2.1 (January 14th, 2012)
4
+
5
+ Refactored the gem; Wrote tests; prepare for release to rubygems.org
6
+
7
+ ##0.2.0 (January 12th, 2012)
8
+
9
+ Converted the plugin to a gem.
10
+
11
+ ##0.1.1 (January 24th, 2010)
12
+
13
+ Fixed a bug that was not converting the dimensions properly if the dimensions were formatted as a fraction.
14
+
15
+ ##0.1.0 (January 22nd, 2010)
16
+
17
+ initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in artworker.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 dataLAB
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,178 @@
1
+ #Artworker
2
+
3
+ The Artworker gem provides many of the basic functions needed when dealing with a collection of different fine artwork and artists. The gem does this by providing custom attributes in an easy to use way that are universally needed (based on museum standards) when dealing with artwork and artists.
4
+
5
+ ##Installation
6
+
7
+ gem install artworker
8
+
9
+ ##Usage
10
+
11
+ ###In Your Artwork Model
12
+
13
+ In the migration file for your artwork model, make sure you have columns for the following standard artwork attributes:
14
+
15
+ * Title Column => Either string or text.
16
+ * Date Column => Either string or text.
17
+ * Height Column => Decimal, that defaults to 0.
18
+ * Width Column => Decimal, that defaults to 0.
19
+ * Depth Column => Decimal, that defaults to 0.
20
+
21
+ Optionally, you can define other columns for artworker. Those columns can provide added functionality to override the defaults:
22
+
23
+ * Use Fractions Column => Boolean, default can be set to true if you want to use fractions instead of decimals.
24
+ * Use Metric System Column => Boolean, default can be set to true if you want to use centimeters instead of inches.
25
+
26
+ You can also assign other dimension types like paper, or framed, or base. Simply add those dimensions as decimal columns, making sure they default to 0.
27
+
28
+ Here is a sample migration that includes the basic columns, optional columns, and columns to record the frame dimensions:
29
+
30
+ class CreateArtworks < ActiveRecord::Migration
31
+ def self.up
32
+ create_table :artworks do |t|
33
+ t.string :title
34
+ t.string :date
35
+ t.decimal :height, :null => false, :default => 0
36
+ t.decimal :width, :null => false, :default => 0
37
+ t.decimal :depth, :null => false, :default => 0
38
+ t.decimal :framed_height, :null => false, :default => 0
39
+ t.decimal :framed_width, :null => false, :default => 0
40
+ t.decimal :framed_depth, :null => false, :default => 0
41
+ t.boolean :use_fractions, :default => true, :null => false
42
+ t.boolean :use_metric, :default => false, :null => false
43
+ t.timestamps
44
+ end
45
+ end
46
+
47
+ def self.down
48
+ drop_table :artworks
49
+ end
50
+ end
51
+
52
+ Once you have created your migration file and migrated your database. You can add the `uses_artworker_artwork` command to your model. You may alter the options to match the columns in your database (though it may not be necessary if your columns match the default options). Here is the sample usage of the `uses_artworker_artwork` command for the model based on the above sample migration:
53
+
54
+ uses_artworker_artwork :title => :title,
55
+ :date => :date,
56
+ :use_fractions => :use_fractions,
57
+ :use_metric => :use_metric,
58
+ :dimensions => { :dimensions => [:height, :width, :depth], :framed_dimensions => [:framed_height, :framed_width, :framed_depth]}
59
+
60
+ You should now be able to use the attributes that Artworker provides. Below is a list of those attributes for the sample model:
61
+
62
+ title_with_date
63
+ italic_title_with_date
64
+ height
65
+ width
66
+ depth
67
+ framed_height
68
+ framed_width
69
+ framed_depth
70
+ height_in_inches
71
+ height_in_centimeters
72
+ width_in_inches
73
+ width_in_centimeters
74
+ depth_in_inches
75
+ depth_in_centimeters
76
+ framed_height_in_inches
77
+ framed_height_in_centimeters
78
+ framed_width_in_inches
79
+ framed_width_in_centimeters
80
+ framed_depth_in_inches
81
+ framed_depth_in_centimeters
82
+ dimensions
83
+ dimensions_in_inches
84
+ dimensions_in_centimeters
85
+ framed_dimensions
86
+ framed_dimensions_in_inches
87
+ framed_dimensions_in_centimeters
88
+
89
+ ###In Your Artist Model
90
+
91
+ In the migration file for your artist model, make sure you have columns for the following standard artist attributes:
92
+
93
+ * First Name Column => Either string or text.
94
+ * Last Name Column => Either string or text.
95
+ * Birth Date Column => Either integer, string or text.
96
+ * Death Date Column => Either integer, string or text.
97
+ * Nationlity Column => Either string or text.
98
+
99
+ Here is a sample migration that includes the basic columns:
100
+
101
+ class CreateArtists < ActiveRecord::Migration
102
+ def self.up
103
+ create_table :artists do |t|
104
+ t.string :firstname
105
+ t.string :lastname
106
+ t.string :birth
107
+ t.string :death
108
+ t.string :nationality
109
+ t.timestamps
110
+ end
111
+ end
112
+
113
+ def self.down
114
+ drop_table :artists
115
+ end
116
+ end
117
+
118
+ Once you have created your migration file and migrated your database. You can add the `uses_artworker_artist` command to your model. You may alter the options to match the columns in your database (though it may not be necessary if your columns match the default options). Here is the sample usage of the `uses_artworker_artist` command for the model based on the above sample migration:
119
+
120
+ uses_artworker_artist :firstname => :firstname,
121
+ :lastname => :lastname,
122
+ :birth => :birth,
123
+ :death => :death,
124
+ :nationality => :nationality
125
+
126
+ You should now be able to use the attributes that Artworker provides. Below is a list of those attributes for the sample model:
127
+
128
+ fullname
129
+ dates
130
+ fullname_with_dates
131
+ fullname_with_nationality_and_dates
132
+
133
+ ##Troubleshooting and FAQs
134
+
135
+ ###Why did you make this gem?
136
+
137
+ There's only so many times that you can write the same code in project to project before you get really sick of it. We've made enough sites for organizations in the art world to know this will alleviate our need for repetitious code.
138
+
139
+ ###What are the default options?
140
+
141
+ For the artwork options, the defaults are:
142
+
143
+ :title => :title
144
+ :date => :date
145
+ :use_fractions => :use_fractions (or false if column does not exist)
146
+ :use_metric => :use_metric (or false if column does not exist)
147
+ :dimensions => { :dimensions => [:height, :width, :depth] }
148
+
149
+ For the artist options, the defaults are:
150
+
151
+ :firstname => :firstname
152
+ :lastname => :lastname
153
+ :birth => :birth
154
+ :death => :death
155
+ :nationality => :nationality
156
+
157
+ ###The fractions aren't formatting properly in an input field?
158
+
159
+ Yes, this is as Rails intended. You can override this by explicitly declaring the value of the input field.
160
+
161
+ ###Why can't this gem generate a standard migration, model, controller, etc. for me?
162
+
163
+ Most people have their own preference when it comes to scaffold generation, and they usually go so far as to create their own. It doesn't seem like putting yet another scaffold out in the wild makes much sense.
164
+
165
+ ###Why doesn't this gem also handle images?
166
+
167
+ Everybody has their own methods for working with images, so it doesn't seem too advantageous at this point to include that functionality. With that being said, it may get added in the future.
168
+
169
+ ###Where are the tests?
170
+
171
+ Glad you asked! The testing environment is rspec, and the tests can be found in the spec directory.
172
+
173
+ ##Development
174
+ This project can be found on github at the following URL.
175
+
176
+ http://github.com/datalab/Artworker/
177
+
178
+ We encourage you to fork this project and make any changes you would like!
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/artworker.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "artworker/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "artworker"
7
+ s.version = Artworker::VERSION
8
+ s.authors = ["dataLAB"]
9
+ s.email = ["info@datalabprojects.com"]
10
+ s.homepage = "https://github.com/datalab/Artworker"
11
+ s.summary = %q{Gem that provides custom attributes for fine artwork and artist.}
12
+ s.description = %q{Gem that provides custom attributes for fine artwork and artist.}
13
+
14
+ s.rubyforge_project = "Artworker"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify development and runtime depencies here;
22
+ s.add_dependency "railties", ">= 3.1.0"
23
+ s.add_dependency "activerecord", ">= 3.1.0"
24
+ s.add_dependency "activesupport", ">= 3.1.0"
25
+
26
+ # specify any dependencies here;
27
+ s.add_development_dependency "rspec"
28
+ s.add_development_dependency "rake"
29
+ s.add_development_dependency "factory_girl_rails"
30
+ s.add_development_dependency "sqlite3"
31
+
32
+ # specify any runtime dependencies here;
33
+ # s.add_runtime_dependency "rest-client"
34
+
35
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require "artworker"
@@ -0,0 +1,85 @@
1
+ module Artworker
2
+ module Artist
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ def uses_artworker_artist(options = {})
11
+ default_options ||= {
12
+ :firstname => :firstname,
13
+ :lastname => :lastname,
14
+ :birth => :birth,
15
+ :death => :death,
16
+ :nationality => :nationality
17
+ }
18
+ options = default_options.merge(options)
19
+ include Artworker::Artist::InstanceMethods
20
+ # options = default_options.merge(options)
21
+ #
22
+ # Artworker::Artists.set_artist_functions( options[:firstname],
23
+ # options[:lastname],
24
+ # options[:birth],
25
+ # options[:death],
26
+ # options[:nationality])
27
+ #
28
+ # include Artworker::Artists
29
+ end
30
+
31
+ end
32
+
33
+ module InstanceMethods
34
+
35
+ def fullname
36
+ "#{self.firstname} #{self.lastname}".strip
37
+ end
38
+
39
+ def dates
40
+ if !self.birth.blank?
41
+ if !self.death.blank?
42
+ "#{self.birth} - #{self.death}"
43
+ else
44
+ "b. #{self.birth}"
45
+ end
46
+ elsif !self.death.blank?
47
+ "d. #{self.death}"
48
+ end
49
+ end
50
+
51
+ def fullname_with_dates
52
+ if !fullname.blank?
53
+ if !dates.blank?
54
+ "#{fullname} (#{dates})"
55
+ else
56
+ "#{fullname}"
57
+ end
58
+ elsif !dates.blank?
59
+ "#{dates}"
60
+ end
61
+ end
62
+
63
+ def fullname_with_nationality_and_dates
64
+ if !fullname.blank?
65
+ if !self.nationality.blank?
66
+ if !dates.blank?
67
+ "#{fullname} (#{self.nationality}, #{dates})"
68
+ else
69
+ "#{fullname} (#{self.nationality})"
70
+ end
71
+ else
72
+ "#{fullname_with_dates}"
73
+ end
74
+ elsif !self.nationality.blank?
75
+ if !dates.blank?
76
+ "#{self.nationality}, #{dates}"
77
+ else
78
+ "#{self.nationality}"
79
+ end
80
+ end
81
+ end
82
+
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,50 @@
1
+ module Artworker
2
+ module Artwork
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ def uses_artworker_artwork(options = {})
11
+ default_options ||= {
12
+ :title => :title,
13
+ :date => :date,
14
+ :use_fractions => :use_fractions,
15
+ :use_metric => :use_metric,
16
+ :dimensions => { :dimensions => [:height,:width,:depth] }
17
+ }
18
+ options = default_options.merge(options)
19
+ Artworker::Dimensions.set_dimensions_functions( options[:dimensions],
20
+ options[:use_fractions],
21
+ options[:use_metric])
22
+ include Artworker::Dimensions
23
+ include Artworker::Fractions
24
+ include Artworker::Artwork::InstanceMethods
25
+ end
26
+
27
+ end
28
+
29
+ module InstanceMethods
30
+
31
+ def title_with_date
32
+ if !self.title.blank?
33
+ !self.date.blank? ? "#{self.title}, #{self.date}" : "#{self.title}"
34
+ elsif !self.date.blank?
35
+ "#{self.date}"
36
+ end
37
+ end
38
+
39
+ def italic_title_with_date
40
+ if !self.title.blank?
41
+ !self.date.blank? ? "<em>#{self.title}</em>, #{self.date}" : "<em>#{self.title}</em>"
42
+ elsif !self.date.blank?
43
+ "#{self.date}"
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,11 @@
1
+ require "active_record/railtie"
2
+ require "active_support/core_ext"
3
+
4
+ module Artworker
5
+ class Railtie < Rails::Railtie
6
+ if defined?(ActiveRecord::Base)
7
+ ActiveRecord::Base.send :include, Artworker::Artist
8
+ ActiveRecord::Base.send :include, Artworker::Artwork
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,130 @@
1
+ module Artworker
2
+ module Dimensions
3
+
4
+ def self.set_dimensions_functions(dimensions, use_fractions, use_metric)
5
+ @@use_fractions = "self.#{use_fractions}"
6
+ @@use_metric = "self.#{use_metric}"
7
+
8
+ format_total_dimensions(dimensions)
9
+ format_individual_dimensions(dimensions)
10
+ end
11
+
12
+ def self.format_individual_dimensions(dimensions)
13
+ dimensions.each do |dimension_collection|
14
+ dimension_collection[1].each do |dimension|
15
+
16
+ define_method "#{dimension}" do
17
+ Artworker::Dimensions.read_dimension(read_attribute(dimension),fractions?) unless read_attribute(dimension).nil?
18
+ end
19
+
20
+ define_method "#{dimension}_in_centimeters" do
21
+ if read_attribute(dimension) && read_attribute(dimension) > 0
22
+ metric? ? eval("self.#{dimension.to_s}") : convert_to_centimeters(eval("self.#{dimension.to_s}"))
23
+ end
24
+ end
25
+
26
+ define_method "#{dimension}_in_inches" do
27
+ if read_attribute(dimension) && read_attribute(dimension) > 0
28
+ metric? ? Artworker::Fractions.round_to_nearest_fraction(convert_to_inches(eval("self.#{dimension.to_s}")).to_s, "1/16") : eval("self.#{dimension.to_s}")
29
+ end
30
+ end
31
+
32
+ define_method "#{dimension}=" do |d|
33
+ new_depth = Artworker::Dimensions.write_dimension(d)
34
+ write_attribute(dimension, new_depth)
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+
41
+ def self.format_total_dimensions(dimensions)
42
+ dimensions.each do |dimension_type|
43
+
44
+ define_method "#{dimension_type[0]}" do
45
+ dim_array = []
46
+ dimension_type[1].each do |dimension_entry|
47
+ dimension_entry = eval "self.#{dimension_entry}"
48
+ dim = dimension_entry unless dimension_entry.blank?
49
+ dim_array << dim
50
+ end
51
+ if metric?
52
+ suffix = " centimeters"
53
+ else
54
+ suffix = " inches"
55
+ end
56
+ total_dimensions = dim_array.compact.join(' x ') + suffix unless dim_array.compact.join(' x ') == ''
57
+ end
58
+
59
+ define_method "#{dimension_type[0]}_in_inches" do
60
+ dim_array = []
61
+ dimension_type[1].each do |dimension_entry|
62
+ dimension_entry = eval "self.#{dimension_entry}_in_inches"
63
+ dim = dimension_entry unless dimension_entry.blank?
64
+ dim_array << dim
65
+ end
66
+ suffix = " inches"
67
+ total_dimensions = dim_array.compact.join(' x ') + suffix unless dim_array.compact.join(' x ') == ''
68
+ end
69
+
70
+ define_method "#{dimension_type[0]}_in_centimeters" do
71
+ dim_array = []
72
+ dimension_type[1].each do |dimension_entry|
73
+ dimension_entry = eval "self.#{dimension_entry}_in_centimeters"
74
+ dim = dimension_entry unless dimension_entry.blank?
75
+ dim_array << dim
76
+ end
77
+ suffix = " centimeters"
78
+ total_dimensions = dim_array.compact.join(' x ') + suffix unless dim_array.compact.join(' x ') == ''
79
+ end
80
+
81
+ end
82
+ end
83
+
84
+ def self.read_dimension(dimension,use_fractions)
85
+ if dimension > 0
86
+ returned_dimension = dimension && (use_fractions ? Artworker::Fractions.round_to_nearest_fraction(dimension.to_s, "1/16") : dimension.to_s)
87
+ else
88
+ returned_dimension = ""
89
+ end
90
+ returned_dimension = returned_dimension.to_i unless returned_dimension != returned_dimension.to_i
91
+ return returned_dimension
92
+ end
93
+
94
+ def self.write_dimension(dimension)
95
+ if dimension.blank?
96
+ dimension = 0
97
+ end
98
+ new_dimension = Artworker::Fractions.to_f(dimension)
99
+ return new_dimension
100
+ end
101
+
102
+ protected
103
+
104
+ def fractions?
105
+ eval @@use_fractions
106
+ rescue
107
+ false
108
+ end
109
+
110
+ def metric?
111
+ eval @@use_metric
112
+ rescue
113
+ false
114
+ end
115
+
116
+ def convert_to_inches(dimension)
117
+ float_value = (dimension.to_f * 0.393700).round(2)
118
+ float_value = float_value.to_i if float_value == float_value.to_i
119
+ return float_value
120
+
121
+ end
122
+
123
+ def convert_to_centimeters(dimension)
124
+ float_value = (Artworker::Fractions.to_f(dimension).to_f * 2.54).round(2)
125
+ float_value = float_value.to_i if float_value == float_value.to_i
126
+ return float_value
127
+ end
128
+
129
+ end
130
+ end
@@ -0,0 +1,107 @@
1
+ require 'rational'
2
+ module Artworker
3
+ module Fractions
4
+
5
+ #This code is derived from Chris O'Sullivan's "Fractional" at http://github.com/thechrisoshow/fractional
6
+
7
+ [:+, :-, :*, :/].each do |math_operator|
8
+ define_method(math_operator) do |another_fraction|
9
+ Artworker::Fractions.new(Artworker::Fractions.to_s(self.to_f.send(math_operator, another_fraction.to_f)))
10
+ end
11
+ end
12
+
13
+ def self.to_f(value=0)
14
+ result = 0
15
+
16
+ if mixed_fraction?(value)
17
+ whole, numerator, denominator = value.scan(/(\-?\d*)\s(\d+)\/(\d+)/).flatten
18
+
19
+ result = (numerator.to_f / denominator.to_f) + whole.to_f.abs
20
+
21
+ result = whole.to_f > 0 ? result : -result
22
+ elsif single_fraction?(value)
23
+ numerator, denominator = value.split("/")
24
+ result = numerator.to_f / denominator.to_f
25
+ else
26
+ result = value.to_f
27
+ end
28
+
29
+ result
30
+ end
31
+
32
+ def self.to_s(value=0, args={})
33
+ whole_number = value.to_f.truncate.to_i
34
+
35
+ if whole_number == 0
36
+ fractional_part_to_string(value, args[:to_nearest])
37
+ else
38
+ decimal_point_value = get_decimal_point_value(value.to_f)
39
+ return whole_number.to_s if decimal_point_value == 0
40
+
41
+ fractional_part = fractional_part_to_string(decimal_point_value.abs, args[:to_nearest])
42
+
43
+ if (fractional_part == "1") || (fractional_part == "0")
44
+ (whole_number + fractional_part.to_i).to_s
45
+ else
46
+ whole_number.to_s + " " + fractional_part
47
+ end
48
+ end
49
+ end
50
+
51
+ def self.round_to_nearest_fraction(value=0, to_nearest_fraction)
52
+ if value.is_a? String
53
+ to_nearest_float = to_f(to_nearest_fraction)
54
+
55
+ to_s((self.to_f(value) / to_nearest_float).round * to_nearest_float)
56
+ else
57
+ to_nearest_float = to_f(to_nearest_fraction)
58
+
59
+ (value / to_nearest_float).round * to_nearest_float
60
+ end
61
+
62
+ end
63
+
64
+ private
65
+
66
+ def self.fraction?(value)
67
+ value.to_s.count('/') == 1
68
+ end
69
+
70
+ def self.single_fraction?(value)
71
+ fraction?(value) and !mixed_fraction?(value)
72
+ end
73
+
74
+ def self.mixed_fraction?(value)
75
+ fraction?(value) and value.match(/\-?\d*\s+\d+\/\d+/)
76
+ end
77
+
78
+ def self.get_decimal_point_value(value)
79
+ value - value.truncate
80
+ end
81
+
82
+ def self.fractional_part_to_string(value, round)
83
+ if round
84
+ round_to_nearest_fraction(float_to_rational(value.to_f).to_s, round)
85
+ else
86
+ float_to_rational(value.to_f).to_s
87
+ end
88
+ end
89
+
90
+
91
+ def self.float_to_rational(value)
92
+ if value.nan?
93
+ return Rational(0,0)
94
+ elsif value.infinite?
95
+ return Rational(value<0 ? -1 : 1,0)
96
+ end
97
+ s,e,f = [value].pack("G").unpack("B*").first.unpack("AA11A52")
98
+ s = (-1)**s.to_i
99
+ e = e.to_i(2)
100
+ if e.nonzero? and e<2047
101
+ Rational(s)* Rational(2)**(e-1023)*Rational("1#{f}".to_i(2),0x10000000000000)
102
+ elsif e.zero?
103
+ Rational(s)* Rational(2)**(-1024)*Rational("0#{f}".to_i(2),0x10000000000000)
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,3 @@
1
+ module Artworker
2
+ VERSION = "0.2.1"
3
+ end
data/lib/artworker.rb ADDED
@@ -0,0 +1,54 @@
1
+ module Artworker
2
+ autoload :Artwork, "artworker/artwork"
3
+ autoload :Artist, "artworker/artist"
4
+ end
5
+
6
+ require "artworker/artworker"
7
+ require "artworker/dimensions"
8
+ require "artworker/fractions"
9
+
10
+
11
+
12
+
13
+ # module Artworker
14
+ #
15
+ # def uses_artworker_artwork options = {}
16
+ #
17
+ # default_options ||= {
18
+ # :title => :title,
19
+ # :date => :date,
20
+ # :use_fractions => :use_fractions,
21
+ # :use_metric => :use_metric,
22
+ # :dimensions => { :dimensions => [:height,:width,:depth] }
23
+ # }
24
+ #
25
+ # options = default_options.merge(options)
26
+ #
27
+ # Artworker::Titles.set_title_functions(options[:title],options[:date])
28
+ # Artworker::Dimensions.set_dimensions_functions(options[:dimensions],options[:use_fractions],options[:use_metric])
29
+ #
30
+ # include Artworker::Dimensions
31
+ # include Artworker::Fractions
32
+ # include Artworker::Titles
33
+ #
34
+ # end
35
+ #
36
+ # def uses_artworker_artist options = {}
37
+ #
38
+ # default_options ||= {
39
+ # :firstname => :firstname,
40
+ # :lastname => :lastname,
41
+ # :birth => :birth,
42
+ # :death => :death,
43
+ # :nationality => :nationality
44
+ # }
45
+ #
46
+ # options = default_options.merge(options)
47
+ #
48
+ # Artworker::Artists.set_artist_functions(options[:firstname],options[:lastname],options[:birth],options[:death],options[:nationality])
49
+ #
50
+ # include Artworker::Artists
51
+ #
52
+ # end
53
+ #
54
+ # end
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+
3
+ describe ArtistModels do
4
+
5
+ before(:each) do
6
+ clean_database!
7
+ @artist = Factory(:artist_models, :firstname => "Sample",
8
+ :lastname => "Artist",
9
+ :birth => "1900",
10
+ :death => "2000",
11
+ :nationality => "American")
12
+ end
13
+
14
+ it "should return the artist's fullname" do
15
+ @artist.fullname.should eq "Sample Artist"
16
+ end
17
+
18
+ it "should return the artist's dates" do
19
+ @artist.dates.should eq "1900 - 2000"
20
+ end
21
+
22
+ it "should return the artist's fullname with dates" do
23
+ @artist.fullname_with_dates.should eq "Sample Artist (1900 - 2000)"
24
+ end
25
+
26
+ it "should return the artist's fullname with nationality and dates" do
27
+ @artist.fullname_with_nationality_and_dates.should eq "Sample Artist (American, 1900 - 2000)"
28
+ end
29
+
30
+ end
@@ -0,0 +1,123 @@
1
+ require "spec_helper"
2
+
3
+ describe ArtworkModels do
4
+
5
+ before(:each) do
6
+ clean_database!
7
+ @artwork = Factory(:artwork_models, :title => "Sample Artwork",
8
+ :date => "2012",
9
+ :height => "24.375",
10
+ :width => "36.2",
11
+ :depth => "2.15",
12
+ :framed_height => "26.35",
13
+ :framed_width => "38.65",
14
+ :framed_depth => "3",
15
+ :use_fractions => true,
16
+ :use_metric => false)
17
+ end
18
+
19
+ it "should return the artwork title with date" do
20
+ @artwork.title_with_date.should eq "Sample Artwork, 2012"
21
+ end
22
+
23
+ it "should return the artwork title (italicized) with date" do
24
+ @artwork.italic_title_with_date.should eq "<em>Sample Artwork</em>, 2012"
25
+ end
26
+
27
+ it "should return the default height" do
28
+ @artwork.height.should eq "24 3/8"
29
+ end
30
+
31
+ it "should return the default width" do
32
+ @artwork.width.should eq "36 3/16"
33
+ end
34
+
35
+ it "should return the default depth" do
36
+ @artwork.depth.should eq "2 1/8"
37
+ end
38
+
39
+ it "should return the default framed height" do
40
+ @artwork.framed_height.should eq "26 3/8"
41
+ end
42
+
43
+ it "should return the default framed width" do
44
+ @artwork.framed_width.should eq "38 5/8"
45
+ end
46
+
47
+ it "should return the default framed depth" do
48
+ @artwork.framed_depth.should eq "3"
49
+ end
50
+
51
+ it "should return the height in inches" do
52
+ @artwork.height_in_inches.should eq "24 3/8"
53
+ end
54
+
55
+ it "should return the height in centimeters" do
56
+ @artwork.height_in_centimeters.should eq 61.91
57
+ end
58
+
59
+ it "should return the width in inches" do
60
+ @artwork.width_in_inches.should eq "36 3/16"
61
+ end
62
+
63
+ it "should return the width in centimeters" do
64
+ @artwork.width_in_centimeters.should eq 91.92
65
+ end
66
+
67
+ it "should return the depth in inches" do
68
+ @artwork.depth_in_inches.should eq "2 1/8"
69
+ end
70
+
71
+ it "should return the depth in centimeters" do
72
+ @artwork.depth_in_centimeters.should eq 5.4
73
+ end
74
+
75
+ it "should return the framed height in inches" do
76
+ @artwork.framed_height_in_inches.should eq "26 3/8"
77
+ end
78
+
79
+ it "should return the framed height in centimeters" do
80
+ @artwork.framed_height_in_centimeters.should eq 66.99
81
+ end
82
+
83
+ it "should return the framed width in inches" do
84
+ @artwork.framed_width_in_inches.should eq "38 5/8"
85
+ end
86
+
87
+ it "should return the framed width in centimeters" do
88
+ @artwork.framed_width_in_centimeters.should eq 98.11
89
+ end
90
+
91
+ it "should return the framed depth in inches" do
92
+ @artwork.framed_depth_in_inches.should eq "3"
93
+ end
94
+
95
+ it "should return the framed depth in centimeters" do
96
+ @artwork.framed_depth_in_centimeters.should eq 7.62
97
+ end
98
+
99
+ it "should return the default dimensions" do
100
+ @artwork.dimensions.should eq "24 3/8 x 36 3/16 x 2 1/8 inches"
101
+ end
102
+
103
+ it "should return the dimensions in inches" do
104
+ @artwork.dimensions_in_inches.should eq "24 3/8 x 36 3/16 x 2 1/8 inches"
105
+ end
106
+
107
+ it "should return the dimensions in centimeters" do
108
+ @artwork.dimensions_in_centimeters.should eq "61.91 x 91.92 x 5.4 centimeters"
109
+ end
110
+
111
+ it "should return the default framed dimensions" do
112
+ @artwork.framed_dimensions.should eq "26 3/8 x 38 5/8 x 3 inches"
113
+ end
114
+
115
+ it "should return the framed dimensions in inches" do
116
+ @artwork.framed_dimensions_in_inches.should eq "26 3/8 x 38 5/8 x 3 inches"
117
+ end
118
+
119
+ it "should return the framed dimensions in centimeters" do
120
+ @artwork.framed_dimensions_in_centimeters.should eq "66.99 x 98.11 x 7.62 centimeters"
121
+ end
122
+
123
+ end
@@ -0,0 +1,3 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: spec/artworker.sqlite3
data/spec/factories.rb ADDED
@@ -0,0 +1,22 @@
1
+ include ActionDispatch::TestProcess
2
+
3
+ Factory.define :artist_models do |f|
4
+ f.firstname "Sample"
5
+ f.lastname "Artist"
6
+ f.birth "1900"
7
+ f.death "2000"
8
+ f.nationality "American"
9
+ end
10
+
11
+ Factory.define :artwork_models do |f|
12
+ f.title "Sample Artwork"
13
+ f.date "2012"
14
+ f.height "24"
15
+ f.width "24"
16
+ f.depth "24"
17
+ f.framed_height "26"
18
+ f.framed_width "26"
19
+ f.framed_depth "26"
20
+ f.use_fractions true
21
+ f.use_metric false
22
+ end
data/spec/models.rb ADDED
@@ -0,0 +1,8 @@
1
+ class ArtworkModels < ActiveRecord::Base
2
+ uses_artworker_artwork :dimensions => { :dimensions => [:height, :width, :depth],
3
+ :framed_dimensions => [:framed_height, :framed_width, :framed_depth]}
4
+ end
5
+
6
+ class ArtistModels < ActiveRecord::Base
7
+ uses_artworker_artist
8
+ end
data/spec/schema.rb ADDED
@@ -0,0 +1,26 @@
1
+ ActiveRecord::Schema.define :version => 0 do
2
+ create_table "artist_models", :force => true do |t|
3
+ t.string "firstname"
4
+ t.string "lastname"
5
+ t.string "birth"
6
+ t.string "death"
7
+ t.string "nationality"
8
+ t.datetime "created_at", :null => false
9
+ t.datetime "updated_at", :null => false
10
+ end
11
+
12
+ create_table "artwork_models", :force => true do |t|
13
+ t.string "title"
14
+ t.string "date"
15
+ t.decimal "height", :default => 0.0, :null => false
16
+ t.decimal "width", :default => 0.0, :null => false
17
+ t.decimal "depth", :default => 0.0, :null => false
18
+ t.decimal "framed_height", :default => 0.0, :null => false
19
+ t.decimal "framed_width", :default => 0.0, :null => false
20
+ t.decimal "framed_depth", :default => 0.0, :null => false
21
+ t.boolean "use_fractions", :default => true, :null => false
22
+ t.boolean "use_metric", :default => false, :null => false
23
+ t.datetime "created_at", :null => false
24
+ t.datetime "updated_at", :null => false
25
+ end
26
+ end
@@ -0,0 +1,49 @@
1
+ $LOAD_PATH << "." unless $LOAD_PATH.include?(".")
2
+
3
+ require "rubygems"
4
+ require "artworker"
5
+ require "factory_girl_rails"
6
+ require "active_record"
7
+ require "active_record/version"
8
+ require "active_support"
9
+ require "pathname"
10
+
11
+ require File.dirname(__FILE__) + "/factories"
12
+
13
+ config = YAML::load(IO.read(File.dirname(__FILE__) + "/database.yml"))
14
+ ActiveRecord::Base.establish_connection(config["test"])
15
+
16
+ database_yml = File.expand_path("../database.yml", __FILE__)
17
+
18
+ if File.exists?(database_yml)
19
+ active_record_configuration = YAML.load_file(database_yml)
20
+
21
+ ActiveRecord::Base.configurations = active_record_configuration
22
+ config = ActiveRecord::Base.configurations["test"]
23
+
24
+ begin
25
+ ActiveRecord::Base.establish_connection("test")
26
+ ActiveRecord::Base.connection
27
+ end
28
+
29
+ ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
30
+ ActiveRecord::Base.default_timezone = :utc
31
+
32
+ ActiveRecord::Base.silence do
33
+ ActiveRecord::Migration.verbose = false
34
+ load(File.dirname(__FILE__) + "/schema.rb")
35
+ load(File.dirname(__FILE__) + "/models.rb")
36
+ end
37
+
38
+ else
39
+ raise "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample"
40
+ end
41
+
42
+ def clean_database!
43
+ models = [ArtistModels,ArtworkModels]
44
+ models.each do |model|
45
+ ActiveRecord::Base.connection.execute "DELETE FROM #{model.table_name}"
46
+ end
47
+ end
48
+
49
+ clean_database!
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: artworker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - dataLAB
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-14 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: &70351170505900 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70351170505900
25
+ - !ruby/object:Gem::Dependency
26
+ name: activerecord
27
+ requirement: &70351170505400 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 3.1.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70351170505400
36
+ - !ruby/object:Gem::Dependency
37
+ name: activesupport
38
+ requirement: &70351170504940 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 3.1.0
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70351170504940
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &70351170504560 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70351170504560
58
+ - !ruby/object:Gem::Dependency
59
+ name: rake
60
+ requirement: &70351170504100 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70351170504100
69
+ - !ruby/object:Gem::Dependency
70
+ name: factory_girl_rails
71
+ requirement: &70351170503680 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70351170503680
80
+ - !ruby/object:Gem::Dependency
81
+ name: sqlite3
82
+ requirement: &70351170503260 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70351170503260
91
+ description: Gem that provides custom attributes for fine artwork and artist.
92
+ email:
93
+ - info@datalabprojects.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - .gitignore
99
+ - .rspec
100
+ - CHANGELOG.md
101
+ - Gemfile
102
+ - LICENSE.txt
103
+ - README.md
104
+ - Rakefile
105
+ - artworker.gemspec
106
+ - init.rb
107
+ - lib/artworker.rb
108
+ - lib/artworker/artist.rb
109
+ - lib/artworker/artwork.rb
110
+ - lib/artworker/artworker.rb
111
+ - lib/artworker/dimensions.rb
112
+ - lib/artworker/fractions.rb
113
+ - lib/artworker/version.rb
114
+ - spec/artworker/artist_spec.rb
115
+ - spec/artworker/artwork_spec.rb
116
+ - spec/database.sample.yml
117
+ - spec/factories.rb
118
+ - spec/models.rb
119
+ - spec/schema.rb
120
+ - spec/spec_helper.rb
121
+ homepage: https://github.com/datalab/Artworker
122
+ licenses: []
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project: Artworker
141
+ rubygems_version: 1.8.15
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Gem that provides custom attributes for fine artwork and artist.
145
+ test_files:
146
+ - spec/artworker/artist_spec.rb
147
+ - spec/artworker/artwork_spec.rb
148
+ - spec/database.sample.yml
149
+ - spec/factories.rb
150
+ - spec/models.rb
151
+ - spec/schema.rb
152
+ - spec/spec_helper.rb