Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Faker::ElectricalComponents #799

Merged
merged 14 commits into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/electrical_components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Faker::ElectricalComponents

```ruby
Faker::ElectricalComponents.active #=> "Transistor"

Faker::ElectricalComponents.passive #=> "Resistor"

Faker::ElectricalComponents.electromechanical #=> "Toggle Switch"
```
1 change: 1 addition & 0 deletions lib/faker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def unique(max_retries = 10_000)
require 'faker/fillmurray'
require 'faker/job'
require 'faker/demographic'
require 'faker/electrical_components'

require 'extensions/array'
require 'extensions/symbol'
Expand Down
16 changes: 16 additions & 0 deletions lib/faker/electrical_components.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Faker
class ElectricalComponents < Base
flexible :electrical_components
def active
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the flexible key above, can these methods be removed and the tests still pass?

Copy link
Contributor Author

@bheim6 bheim6 Jan 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No they can not, I get NoMethodError: undefined method []' for nil:NilClass`` errors for each method if they are not present. I included this code because an error message from the test suite prompted me to: warning: instance variable @flexible_key not initialized.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

fetch('electrical_components.active')
end

def passive
fetch('electrical_components.passive')
end

def electromechanical
fetch('electrical_components.electromechanical')
end
end
end
5 changes: 5 additions & 0 deletions lib/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,8 @@ en:
demonym: ["Afghan","Albanian","Algerian","American","Andorran","Angolan","Argentine","Armenian","Aromanian","Aruban","Australian","Austrian","Azerbaijani","Bahamian","Bahraini","Bangladeshi","Barbadian","Basotho","Basque","Belarusian","Belgian","Belizean","Bermudian","Bissau-Guinean","Boer","Bosniak","Brazilian","Breton","Briton","British Virgin Islander","Bruneian","Bulgarian","Burkinabè","Burundian","Cambodian","Cameroonian","Canadian","Catalan","Cape Verdean","Chadian","Chilean","Chinese","Colombian","Comorian","Congolese","Croatian","Cuban","Cypriot","Czech","Dane","Dominican","Dutch","East Timorese","Ecuadorian","Egyptian","Emirati","English","Eritrean","Estonian","Ethiopian","Falkland Islander","Faroese","Finn",Fijian","Filipino","French","Georgian","German","Ghanaian","Gibraltar","Greek","Grenadian","Guatemalan","French Guianan","Guinean","Guyanese","Haitian","Honduran","Hong Konger","Hungarian","Icelander","I-Kiribati","Indian","Indonesian","Iranian","Iraqi","Irish","Israeli","Italian","Ivoirian","Jamaican","Japanese","Jordanian","Kazakh","Kenyan","Korean","Kosovar","Kurd","Kuwaiti","Kyrgyz","Lao","Latvian","Lebanese","Liberian","Libyan","Liechtensteiner","Lithuanian","Luxembourger","Macanese","Macedonian","Malagasy","Malaysian","Malawian","Maldivian","Malian","Maltese","Manx","Mauritian","Mexican","Moldovan","Moroccan","Mongolian","Montenegrin","Namibian","Nepalese","New Zealander","Nicaraguan","Nigerien","Nigerian","Norwegian","Pakistani","Palauan","Palestinian","Panamanian","Papua New Guinean","Paraguayan","Peruvian","Pole","Portuguese","Puerto Rican","Quebecer","Romanian","Russian","Rwandan","Salvadoran","São Toméan","Saudi","Scottish","Senegalese","Serb","Sierra Leonean","Singaporean","Sindhian","Slovak","Slovene","Somali","Somalilander","South African","Spaniard","Sri Lankan","St Lucian","Sudanese","Surinamese","Swede","Swiss","Syriac","Syrian","Tajik","Taiwanese","Tanzanian","Thai","Tibetan","Tobagonian","Trinidadian","Tunisian","Turk","Tuvaluan","Ugandan","Ukrainian","Uruguayan","Uzbek","Vanuatuan","Venezuelan","Vietnamese","Welsh","Yemeni","Zambian","Zimbabwean"]
educational_attainment: ["No schooling completed", "Nursery school", "Kindergarten", "Grade 1 though 11", "12th grade - No Diploma", "Regular high school diploma", "GED or alternative credential", "Some college", "Associate's degree", "Bachelor's degree", "Master's degree", "Professional degree", "Doctorate degree"]
marital_status: ["Married", "Widowed", "Divorced", "Separated", "Never married"]

electrical_components:
active: ["Diode", "LED", "Rectifier", "Transistor", "JFET", "MOSFET", "Integrated Circuit", "LCD", "Cathode Ray Tube", "Vacuum Tube", "Battery", "Fuel Cell", "Power Supply"]
passive: ["Resistor", "Potentiometer", "Trim Pot", "Varistor", "Capacitor", "Varicap Diode", "Inductor", "Transformer", "Generator", "Motor", "Solenoid", "Magnetic Amplifier", "Speaker", "Motion Sensor", "Accelerometer", "Thermocouple", "Antenna", "Oscillator", "Breadboard"]
electromechanical: ["Piezoelectric device", "crystal", "Ultrasonic Motor", "Terminal", "Socket", "Power Cord", "Toggle Switch", "Slide Switch", "DIP Switch", "Footswitch", "Keypad", "Circuit Breaker", "Fuse", "Printed Circuit Board"]
19 changes: 19 additions & 0 deletions test/test_faker_electrical_components.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')

class TestFakerElectricalComponents < Test::Unit::TestCase
def setup
@tester = Faker::ElectricalComponents
end

def test_active
assert @tester.active.match(/\w+/)
end

def test_passive
assert @tester.passive.match(/\w+/)
end

def test_electromechanical
assert @tester.electromechanical.match(/\w+/)
end
end