Created
February 10, 2015 00:23
-
-
Save gregory/116aaaa8b0bdde0ee5d0 to your computer and use it in GitHub Desktop.
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
class ParserStrategy | |
def parse | |
raise NotImplementedError | |
end | |
end | |
class GoogleParser < ParserStrategy | |
def parse | |
GoogleTranslate.translate raw | |
end | |
def raw | |
result_from_dog_com | |
end | |
private | |
def result_from_dog_com | |
end | |
end | |
class TranslateTemplate | |
attr_reader :data | |
def initialize(data) | |
@data = data | |
end | |
def self.translate(data) | |
new(data).to_hash | |
end | |
def name | |
"NA" | |
end | |
end | |
class GoogleTranslate < Template | |
def name | |
data[:google_specific_name] | |
end | |
end | |
GoogleParser.parse > {name: 'google name' } | |
FOOParser.parse > {name: 'foo name' } | |
BARParser.parse > {name: 'NA' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment