-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update languages - added search functions & tests
- Loading branch information
Showing
4 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,38 @@ | ||
# This is a 1:1 representation of ISO 639-2. | ||
# It is built on initialization with a rake task, and not further touched. | ||
# attribute alpha_3_bibliographic always has a distinct 3 character value | ||
# alpha_2 will have either a 2 character value or and empty string ('') | ||
# english_name or french_name may be more than one word long | ||
# (e.g. 'English, Middle (1100-1500)', 'Filipino; Pilipino','Finno-Ugrian languages') | ||
# and many of the languages have multiple version (e.g. there are 4 variations of German) | ||
class Language < ActiveRecord::Base | ||
|
||
include Housekeeping::Users | ||
|
||
# Scopes | ||
scope :eng_name_contains, ->(name) {where('english_name ILIKE ?', "%#{name}%")} # non-case sensitive comparison | ||
|
||
#Validations | ||
validates_presence_of :english_name, :alpha_3_bibliographic | ||
|
||
#returns nil or single object | ||
def self.exact_abr(abbr) | ||
a = where('alpha_3_bibliographic = ?', abbr).to_a | ||
if a.count == 0 | ||
return nil | ||
else | ||
return a[0] | ||
end | ||
end | ||
|
||
#returns nil or single object | ||
def self.exact_eng(name) | ||
a = where('english_name = ?', name).to_a | ||
if a.count == 0 | ||
return nil | ||
else | ||
return a[0] | ||
end | ||
|
||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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