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 update_or_create_expert_category(category_ids) | |
categories = Category.find(category_ids.reject {|x| x.empty?}) | |
@expert.categories.each do |category| | |
unless categories.include? category | |
expert_category.destroy | |
end | |
unless @expert.categories.include? category | |
ExpertCategory.create(expert: @expert, category: category) | |
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
require "date" | |
REGEXP = /^(?<gender>[12])(?<year>\d{2})(?<month>\d{2})(?<zip>\d{2})(\d{6})(?<key>\d{2})/ | |
DEPARTMENTS = { | |
"75" => "Paris", | |
"76" => "Seine Maritime" | |
} | |
def ssn_info(ssn) | |
# TODO "a man, born in March, 1986 in Paris." |
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
# Rubular regexp pour créer des groupes de matching | |
# Appeller la methode match afin de constituer les groupes | |
# branche afin de déterminer le genre | |
# Mois en lettres, hash => clé mois, valeur => mois en lettres | |
require"date" | |
SSN_FORMAT = /^(?<sexe>1|2)(?<year>\d{2})(?<month>\d{2})(?<state>\d{2})(\d{6})(?<key>\d{2})$/ | |
DPT = { |
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
require 'open-uri' # Open an url | |
require 'nokogiri' # HTML ==> Nokogiri Document | |
url = "http://www.imdb.com/chart/top" | |
base_url = "http://www.imdb.com" | |
html_file = open(url) | |
html_doc = Nokogiri::HTML(html_file) | |
movies_doc = html_doc.search('.titleColumn a') |
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
require "open-uri" | |
require "json" | |
puts "What is your Github nickname ?" | |
print "> " | |
username = gets.chomp | |
url = "https://api.github.com/users/#{username}" | |
# calls the api |
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
require "date" | |
REG = /^(?<gender>[12])(?<year>\d{2})(?<month>\d{2})(?<dept>\d{2})\d{6}(?<key>\d{2})/ | |
DEPARTEMENT = { | |
"75" => "Paris", | |
"76" => "Seine Maritime" | |
} | |
def ssn_info(ssn) | |
# TODO => "a man, born in March, 1986 in Paris." | |
ssn = ssn.gsub(" ","") | |
result = ssn.match(REG) |
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
require 'open-uri' | |
require 'nokogiri' | |
url = 'http://www.letscookfrench.com/recipes/find-recipe.aspx?aqt=chocolate' | |
html_file = open(url).read | |
html_doc = Nokogiri::HTML(html_file) | |
html_doc.search('.m_contenu_resultat').each do |element| | |
p element.search('.m_titre_resultat a').text |
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
require 'open-uri' # Open an url | |
require 'nokogiri' # HTML ==> Nokogiri Document | |
url = "http://www.imdb.com/chart/top" | |
html = open(url).read | |
html_doc = Nokogiri::HTML(html) | |
html_doc.search('.titleColumn a').each do |element| | |
title = element.text | |
link = element.attribute('href') |
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
require "sqlite3" | |
require_relative "../models/employee" | |
class EmployeesRepository | |
def initialize | |
@db = SQLite3::Database.new('food_delivery.db') | |
@db.results_as_hash = true | |
@employees = [] | |
load_from_db | |
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
# we use the match method to extract the data from original string | |
# find the gender | |
# find the birth year | |
# find the birth month | |
# find the dept | |
# validate the number | |
require 'date' | |
DEPT = { | |
75 => "Paris", | |
76 => "Seine-Maritime" |
OlderNewer