Class: MagicDoor

Inherits:
Object
  • Object
show all
Defined in:
lib/magic_door.rb

Defined Under Namespace

Modules: CssMethods

Constant Summary collapse

VERSION =
Gem::Specification.load(File.expand_path("../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

Class Method Summary collapse

Instance Method Summary collapse

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 image location.

destination_path

Prefix for file_name location.

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(options = {})
  self.css = self.class.defaults[:css]
  self.css = options[:css] if options[:css]
  %w(source_path destination_path split_at image text file_name).each do |name|
    n = name.to_sym
    self.send("#{n}=", options[n] || self.class.defaults[n])
  end
end

Instance Attribute Details

#canvasObject

:nodoc:



61
62
63
# File 'lib/magic_door.rb', line 61

def canvas
  @canvas
end

#cssObject

Returns the value of attribute css.



51
52
53
# File 'lib/magic_door.rb', line 51

def css
  @css
end

#destination_pathObject

Returns the value of attribute destination_path.



55
56
57
# File 'lib/magic_door.rb', line 55

def destination_path
  @destination_path
end

#file_nameObject

Returns the value of attribute file_name.



55
56
57
# File 'lib/magic_door.rb', line 55

def file_name
  @file_name
end

#imageObject

Returns the value of attribute image.



51
52
53
# File 'lib/magic_door.rb', line 51

def image
  @image
end

#source_pathObject

Returns the value of attribute source_path.



55
56
57
# File 'lib/magic_door.rb', line 55

def source_path
  @source_path
end

#split_atObject

Returns the value of attribute split_at.



55
56
57
# File 'lib/magic_door.rb', line 55

def split_at
  @split_at
end

#textObject

Returns the value of attribute text.



55
56
57
# File 'lib/magic_door.rb', line 55

def text
  @text
end

Class Method Details

.defaultsObject

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=(options)
  @@defaults = options
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(options = {})
  compose_button
  draw
  write_file(options[:as] || file_name)
end