This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def applicable?(order) | |
| self.active? && | |
| (self.effective_at..self.end_at).include?(Date.today) && | |
| order.detail_total > minimum_order_total && | |
| compatible?(order.applied_discounts.dup.reject{|d| d == self }) && | |
| ! allowed_details(order).empty? | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # hack searchlogic to work with date_select / datetime_select in search form | |
| module Searchlogic | |
| class Search | |
| # Accepts a hash of conditions. | |
| def conditions=(values) | |
| values.each do |condition, value| | |
| if condition =~ /(.*)\(1i\)$/ | |
| date_scope_name = $1 | |
| date_parts = (1..6).to_a.map do |idx| | |
| values.delete("#{ date_scope_name }(#{ idx }i)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Discount | |
| # name | |
| # code | |
| # effective_at | |
| # ends_at | |
| # type # (DollarOff, PercentOff, FreeShipping..) | |
| # promotion? | |
| # customer_exclusive? | |
| # amount | |
| # minimum_total_requirement |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def add_discount(promo_code) | |
| discount = Discount.find_by_code(promo_code) | |
| if discount && discount.applicable?(self) | |
| if discount.customer_exclusive? | |
| discount_assignment = discount.assignments.find_by_user_id(user.id) | |
| discount_assignment.update_attributes(:sales_order_id => self.id) | |
| else | |
| discount_assignments.create(:discount => discount) | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby -wKU | |
| require 'nokogiri' | |
| require 'time' | |
| receipt_file = ARGV.shift || '' | |
| if receipt_file.empty? | |
| puts "please point me to your receipt file" | |
| exit 1 | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Product | |
| STATES_INDEX_CONSTANTS = { | |
| :active => 1, | |
| :inactive => 2, | |
| # ...whatever... | |
| } | |
| define_index do | |
| has "CASE `products`.`state` #{ STATES_INDEX_CONSTANTS.map{|k,v| "WHEN '#{k}' THEN #{v}"}.join } END", :as => :state | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // WINDOWS | |
| var masterWindow = Ti.UI.createWindow({ backgroundColor:'#ffffff', title: 'Root' }); | |
| var childWindow = Ti.UI.createWindow({ backgroundColor:'#ffffff', title: 'Child' }); | |
| // data for root table view | |
| var mainNavGroups = [ | |
| { title: "Foo" }, | |
| { title: "Bar" } | |
| ]; | |
| var masterRootNavTable = Titanium.UI.createTableView({ data: mainNavGroups }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def self.resolve(brandish) | |
| case brandish | |
| when Brand | |
| brandish | |
| when Fixnum | |
| find(brandish) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # USAGE: Hash.from_xml:(YOUR_XML_STRING) | |
| require 'nokogiri' | |
| # modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#1231297 | |
| class Hash | |
| class << self | |
| def from_xml(xml_io) | |
| begin | |
| result = Nokogiri::XML(xml_io) | |
| return { result.root.name.to_sym => xml_node_to_hash(result.root)} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module ResponseHelpers | |
| def response_dom | |
| html = response.try(:body) || page.try(:body) | |
| $stderr.puts "WARNING: No response HTML!" if html.blank? | |
| Nokogiri::HTML(html) | |
| end | |
| end | |
| World(ResponseHelpers) |