Class: MagicDoor
- Inherits:
-
Object
- Object
- MagicDoor
- Defined in:
- lib/magic_door.rb
Defined Under Namespace
Modules: CssMethods
Constant Summary collapse
- VERSION =
Gem::Specification.load(File.("../magic_door.gemspec", File.dirname(__FILE__))).version.to_s
- CSS_ALIASES =
{ :attributes => { "color" => "fill", "font-weight" => "font_weight", "font-family" => "font_family", "font-size" => "pointsize", "text-align" => "gravity", }, :values => { "bold" => Magick::BoldWeight, "center" => Magick::CenterGravity, "left" => Magick::WestGravity, "right" => Magick::EastGravity } }
- @@defaults =
{ :css => "text-align: center; padding: 10; color: #000", :split_at => 30, :image => "button.png", :source_path => "", :destination_path => "", :text => "Submit", :file_name => "result.png" }
Instance Attribute Summary collapse
-
#canvas ⇒ Object
:nodoc:.
-
#css ⇒ Object
Returns the value of attribute css.
-
#destination_path ⇒ Object
Returns the value of attribute destination_path.
-
#file_name ⇒ Object
Returns the value of attribute file_name.
-
#image ⇒ Object
Returns the value of attribute image.
-
#source_path ⇒ Object
Returns the value of attribute source_path.
-
#split_at ⇒ Object
Returns the value of attribute split_at.
-
#text ⇒ Object
Returns the value of attribute text.
Class Method Summary collapse
-
.defaults ⇒ Object
Returns defined defaults.
-
.defaults=(options) ⇒ Object
Sets
defaultsfor new object instances.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ MagicDoor
constructor
Instantiate a new object.
-
#save(options = {}) ⇒ Object
Creates the image file.
Constructor Details
#initialize(options = {}) ⇒ MagicDoor
Instantiate a new object. Missing options fallback to defaults.
Options:
- text
-
Text that will be displayed inside the button.
- split_at
-
Location where the image is being split.
- source_path
-
Prefix for
imagelocation. - destination_path
-
Prefix for
file_namelocation. - file_name
-
The name of the file being saved.
95 96 97 98 99 100 101 102 |
# File 'lib/magic_door.rb', line 95 def initialize( = {}) self.css = self.class.defaults[:css] self.css = [:css] if [:css] %w(source_path destination_path split_at image text file_name).each do |name| n = name.to_sym self.send("#{n}=", [n] || self.class.defaults[n]) end end |
Instance Attribute Details
#canvas ⇒ Object
:nodoc:
61 62 63 |
# File 'lib/magic_door.rb', line 61 def canvas @canvas end |
#css ⇒ Object
Returns the value of attribute css.
51 52 53 |
# File 'lib/magic_door.rb', line 51 def css @css end |
#destination_path ⇒ Object
Returns the value of attribute destination_path.
55 56 57 |
# File 'lib/magic_door.rb', line 55 def destination_path @destination_path end |
#file_name ⇒ Object
Returns the value of attribute file_name.
55 56 57 |
# File 'lib/magic_door.rb', line 55 def file_name @file_name end |
#image ⇒ Object
Returns the value of attribute image.
51 52 53 |
# File 'lib/magic_door.rb', line 51 def image @image end |
#source_path ⇒ Object
Returns the value of attribute source_path.
55 56 57 |
# File 'lib/magic_door.rb', line 55 def source_path @source_path end |
#split_at ⇒ Object
Returns the value of attribute split_at.
55 56 57 |
# File 'lib/magic_door.rb', line 55 def split_at @split_at end |
#text ⇒ Object
Returns the value of attribute text.
55 56 57 |
# File 'lib/magic_door.rb', line 55 def text @text end |
Class Method Details
.defaults ⇒ Object
Returns defined defaults
81 82 83 |
# File 'lib/magic_door.rb', line 81 def defaults @@defaults end |
.defaults=(options) ⇒ Object
Sets defaults for new object instances.
76 77 78 |
# File 'lib/magic_door.rb', line 76 def defaults=() @@defaults = end |
Instance Method Details
#save(options = {}) ⇒ Object
Creates the image file.
Returns
Path of the saved file.
Options
- as
-
Alternate way of setting the name of the file being saved. Fallsback to
file_name.
109 110 111 112 113 |
# File 'lib/magic_door.rb', line 109 def save( = {}) draw write_file([:as] || file_name) end |