Skip to content

Instantly share code, notes, and snippets.

@eduzera
Created September 5, 2013 01:23
Show Gist options
  • Save eduzera/6444903 to your computer and use it in GitHub Desktop.
Save eduzera/6444903 to your computer and use it in GitHub Desktop.
#created by: Eduardo Zaghi
#idea base: https://chop-chop.org/order-now.html
require 'action_view'
class Proposal
include ActionView::Helpers::NumberHelper
HTML_PRICE = 150
HTML_HALF_PRICE = HTML_PRICE / 2
CSS3_PRICE = 75
SERVICES = {
rails: {
crud: 150,
sortable: 75,
images_uploads: 75,
publish_model: 75,
publisher_structure: 150,
public_view_dinamic: 75,
send_email: 75
},
markup: {
html_5: 0,
html_5_fluid: 75,
html_5_responsive: 150,
html_5_fluid_responsive: 150
},
stylesheet: {
css_3: 0,
css_3_commented: 9,
web_font: 75
},
javascript: {
jquery: 0,
image_gallery: 150,
carrousel: 75,
slide_show: 150,
lightbox: 75,
menu_dropdown: 75,
custom_scroll: 150,
ajax_form: 150,
google_maps: 75,
video_embed: 75
},
social_btn: {
facebook_like_and_fan_box: 40,
twitter_tweet_and_feed: 40,
google_plus: 40,
share_this_or_add_this: 75
}
}
attr_accessor :title, :pages, :total
def initialize(options={})
@pages = options[:pages]
@total = 0
@title = options[:title] || 'LolDesign Proposal'
end
def process
print_header
calculate
print_footer
end
private
def print_header
puts "\n"
puts @title
puts '-----------------------------------'
end
def print_footer
puts '-----------------------------------'
puts "Total: #{ActionView::Base.new.number_to_currency(@total)}"
end
def calculate
@pages.each_key do |page_name|
sum = page_total(@pages[page_name])
@total += sum
puts "#{page_name}: #{to_currency(sum)}"
end
end
def page_total(included_services)
costs = included_services.inject([]){|array, name| array.push get_service_price(name)}
sum_costs(costs)
end
def get_service_price(name)
find_service(name)
end
def find_service(name)
SERVICES.each_key do |key|
return SERVICES[key][name] if SERVICES[key].has_key?(name)
end
end
def sum_costs(costs)
(html_half_price? ? HTML_HALF_PRICE : HTML_PRICE) + CSS3_PRICE + costs.inject{|sum,x| sum + x }
end
def to_currency(value)
ActionView::Base.new.number_to_currency(value)
end
def html_half_price?
@total > 0
end
end
#static project
Proposal.new(
title: 'Static Project',
pages: {
home: [ :html_5, :css_3, :jquery, :slide_show, :facebook_like_and_fan_box, :twitter_tweet_and_feed, :google_plus, :ajax_form ],
about: [ :html_5, :css_3, :jquery ],
tips_and_recipes: [ :html_5, :css_3, :jquery, :share_this_or_add_this, :image_gallery ],
services: [ :html_5, :css_3, :jquery, :share_this_or_add_this ],
covenants: [ :html_5, :css_3, :jquery ],
contacts: [ :html_5, :css_3, :jquery, :google_maps, :send_email ]
}).process
#dinamic project
Proposal.new(
title: 'Dinamic Project',
pages: {
essentials: [ :publisher_structure ],
home: [ :html_5, :css_3, :jquery, :slide_show, :facebook_like_and_fan_box, :twitter_tweet_and_feed, :google_plus, :ajax_form, :public_view_dinamic ],
about: [ :html_5, :css_3, :jquery, :crud, :public_view_dinamic ],
tips_and_recipes: [ :html_5, :css_3, :jquery, :share_this_or_add_this, :image_gallery, :crud, :images_uploads, :public_view_dinamic ],
services: [ :html_5, :css_3, :jquery, :share_this_or_add_this, :crud, :image_gallery, :sortable, :public_view_dinamic ],
covenants: [ :html_5, :css_3, :jquery, :crud, :sortable ],
contacts: [ :html_5, :css_3, :jquery, :google_maps, :send_email ]
}).process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment