Permalink
Browse files

[FEAT] adding company

  • Loading branch information...
1 parent a839821 commit 692c03dbeffe9434dcffb4014dcbc035d5afdbdc Elad Meidar committed Jun 10, 2014
View
12 app/controllers/api/v1/people_controller.rb
@@ -2,20 +2,12 @@ class Api::V1::PeopleController < Api::V1::BaseController
def index
count = (params[:count] || 1).to_i
+ has_company = params[:with_company].present? ? true : false
people = []
count.times do
- people << Person.new
+ people << Person.new(has_company)
end
- if params[:field] # suppose this value is email
-
- # p.send("email") is the same as p.email
- people = people.map { |p| p.send(params[:field]) }
-
- end
-
-
-
respond_with(people)
end
View
16 app/models/concerns/company.rb
@@ -0,0 +1,16 @@
+class Company
+
+ attr_accessor :name, :slogan, :site, :customer_support
+
+ def initialize
+ self.name = [Faker::Company.name, Faker::Company.suffix].join(" ")
+ self.slogan = Faker::Company.catch_phrase
+ self.site = generate_site
+ self.customer_support = Faker::PhoneNumber.phone_number
+ end
+
+ def generate_site
+ ["www", self.name.downcase.gsub(" ", ""), Faker::Internet.domain_suffix].join(".")
+ end
+
+end
View
16 app/models/person.rb
@@ -1,14 +1,22 @@
-class Person < ActiveRecord::Base
+class Person
- def initialize
- super
+ attr_accessor :email, :name, :ip_address, :bio, :avatar, :phone, :credit_card, :company
+
+ def initialize(has_company = false)
self.email = Faker::Internet.email
self.name = Faker::Name.name
self.ip_address = Faker::Internet.ip_v4_address
self.bio = Faker::Lorem.paragraph
- self.avatar = Faker::Avatar.image
+ self.avatar = Faker::Avatar.image(self.name_slug)
self.phone = Faker::PhoneNumber.cell_phone
self.credit_card = Faker::Finance.credit_card
+ if has_company
+ self.company = Company.new
+ end
+ end
+
+ def name_slug
+ self.name.parameterize
end
end
View
15 db/migrate/20140609025638_create_people.rb
@@ -1,15 +0,0 @@
-class CreatePeople < ActiveRecord::Migration
- def change
- create_table :people do |t|
- t.string :email
- t.string :ip_address
- t.string :name
- t.string :credit_card
- t.text :bio
- t.string :phone
- t.string :avatar
-
- t.timestamps
- end
- end
-end

0 comments on commit 692c03d

Please sign in to comment.