Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Calyhre committed May 14, 2017
0 parents commit ccdaa3e
Show file tree
Hide file tree
Showing 61 changed files with 1,407 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*

/node_modules
/yarn-error.log

.byebug_history
23 changes: 23 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
source 'https://rubygems.org'
ruby '2.4.1'

gem 'puma', '~> 3.7'

gem 'pg', '~> 0.18'
gem 'rails', '~> 5.1.1'

gem 'countries'
gem 'httparty'
gem 'money-rails'
# gem 'sass-rails', '~> 5.0'

group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'jazz_fingers'
end

group :development do
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
186 changes: 186 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (5.1.1)
actionpack (= 5.1.1)
nio4r (~> 2.0)
websocket-driver (~> 0.6.1)
actionmailer (5.1.1)
actionpack (= 5.1.1)
actionview (= 5.1.1)
activejob (= 5.1.1)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.1.1)
actionview (= 5.1.1)
activesupport (= 5.1.1)
rack (~> 2.0)
rack-test (~> 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.1.1)
activesupport (= 5.1.1)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.1.1)
activesupport (= 5.1.1)
globalid (>= 0.3.6)
activemodel (5.1.1)
activesupport (= 5.1.1)
activerecord (5.1.1)
activemodel (= 5.1.1)
activesupport (= 5.1.1)
arel (~> 8.0)
activesupport (5.1.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (8.0.0)
awesome_print (1.7.0)
builder (3.2.3)
byebug (9.0.6)
coderay (1.1.1)
concurrent-ruby (1.0.5)
coolline (0.5.0)
unicode_utils (~> 1.4)
countries (2.0.8)
i18n_data (~> 0.7.0)
money (~> 6.7)
sixarm_ruby_unaccent (~> 1.1)
unicode_utils (~> 1.4)
erubi (1.6.0)
ffi (1.9.18)
globalid (0.4.0)
activesupport (>= 4.2.0)
hirb (0.7.3)
httparty (0.15.2)
multi_xml (>= 0.5.2)
i18n (0.8.1)
i18n_data (0.7.0)
jazz_fingers (4.0.1)
awesome_print (~> 1.6)
hirb (~> 0.7)
pry (~> 0.10)
pry-byebug (~> 3.4)
pry-coolline (~> 0.2)
pry-doc (~> 0.6)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.5)
mime-types (>= 1.16, < 4)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.10.2)
monetize (1.4.0)
money (~> 6.7)
money (6.9.0)
i18n (>= 0.6.4, < 0.9)
money-rails (1.7.0)
activesupport (>= 3.0)
monetize (~> 1.4.0)
money (~> 6.7)
railties (>= 3.0)
multi_xml (0.6.0)
nio4r (2.0.0)
nokogiri (1.7.2)
mini_portile2 (~> 2.1.0)
pg (0.20.0)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-byebug (3.4.2)
byebug (~> 9.0)
pry (~> 0.10)
pry-coolline (0.2.5)
coolline (~> 0.5)
pry-doc (0.10.0)
pry (~> 0.9)
yard (~> 0.9)
puma (3.8.2)
rack (2.0.2)
rack-test (0.6.3)
rack (>= 1.0)
rails (5.1.1)
actioncable (= 5.1.1)
actionmailer (= 5.1.1)
actionpack (= 5.1.1)
actionview (= 5.1.1)
activejob (= 5.1.1)
activemodel (= 5.1.1)
activerecord (= 5.1.1)
activesupport (= 5.1.1)
bundler (>= 1.3.0, < 2.0)
railties (= 5.1.1)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (5.1.1)
actionpack (= 5.1.1)
activesupport (= 5.1.1)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (12.0.0)
rb-fsevent (0.9.8)
rb-inotify (0.9.8)
ffi (>= 0.5.0)
ruby_dep (1.5.0)
sixarm_ruby_unaccent (1.1.1)
slop (3.6.0)
spring (2.0.1)
activesupport (>= 4.2)
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
spring (>= 1.2, < 3.0)
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.0)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (0.19.4)
thread_safe (0.3.6)
tzinfo (1.2.3)
thread_safe (~> 0.1)
unicode_utils (1.4.0)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
yard (0.9.8)

PLATFORMS
ruby

DEPENDENCIES
byebug
countries
httparty
jazz_fingers
listen (>= 3.0.5, < 3.2)
money-rails
pg (~> 0.18)
puma (~> 3.7)
rails (~> 5.1.1)
spring
spring-watcher-listen (~> 2.0.0)

RUBY VERSION
ruby 2.4.1p111

BUNDLED WITH
1.14.6
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# README

This README would normally document whatever steps are necessary to get the
application up and running.

Things you may want to cover:

* Ruby version

* System dependencies

* Configuration

* Database creation

* Database initialization

* How to run the test suite

* Services (job queues, cache servers, search engines, etc.)

* Deployment instructions

* ...
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative 'config/application'

Rails.application.load_tasks
3 changes: 3 additions & 0 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
13 changes: 13 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require_tree .
15 changes: 15 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
* vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require_self
*/
33 changes: 33 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception

before_action do
request.format = :csv
end

def index
games = Game.all.includes(:prices).sort_by(&:title).group_by(&:parsed_game_code)
countries = Price.pluck(:country).uniq.sort
currency = Price.pluck(:currency).include?(params[:currency]) ? params[:currency] : nil

csv = CSV.generate(headers: true) do |rows|
rows << %w(title).concat(countries)
games.each do |code, games|
game = games.first
prices = games.flat_map(&:prices)
row = []
row << game.title
countries.each do |country|
price = prices.detect { |p| p.country === country }
row << (price ? (currency ? price.value.exchange_to(currency) : price.value) : 'NA')
end
# csv << attributes.map{ |attr| user.send(attr) }
rows << row
end
end

respond_to do |format|
format.csv { send_data csv }
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ApplicationHelper
end
2 changes: 2 additions & 0 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationJob < ActiveJob::Base
end
3 changes: 3 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
12 changes: 12 additions & 0 deletions app/models/exchange_rate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class ExchangeRate < ApplicationRecord
def self.get_rate(from_iso_code, to_iso_code)
rate = find_by(from: from_iso_code, to: to_iso_code)
rate.present? ? rate.rate : 0
end

def self.add_rate(from_iso_code, to_iso_code, rate)
exrate = find_or_initialize_by(from: from_iso_code, to: to_iso_code)
exrate.rate = rate
exrate.save!
end
end
13 changes: 13 additions & 0 deletions app/models/game.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Game < ApplicationRecord
REGIONS = %w(americas asia europe)

attribute :game_code, :string
attribute :parsed_game_code, :string
attribute :nsuid, :string
attribute :region, :string
attribute :title, :string
attribute :release_date, :datetime
attribute :cover_url, :string

has_many :prices
end
12 changes: 12 additions & 0 deletions app/models/price.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Price < ApplicationRecord
belongs_to :game

attribute :nsuid, :string
attribute :country, :string, limit: 2
attribute :status, :string
attribute :currency, :string, limit: 3
attribute :value_in_cents, :integer

register_currency :usd
monetize :value_in_cents, as: 'value', with_model_currency: :currency
end
14 changes: 14 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>EshopPrices</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>

<body>
<%= yield %>
</body>
</html>
Loading

0 comments on commit ccdaa3e

Please sign in to comment.