japanese input

26 views
Skip to first unread message

Cristiano de Araujo Bezerra

unread,
Apr 15, 2015, 2:18:05 PM4/15/15
to rubyonra...@googlegroups.com
i need some help. i tried a lot of time using loops but i cannot figure
it out wha i want.

is basicaly this:

i type a letter and i have the output in hiragana but the program can´t
finish untill i press 'q' and if type another letter it joins to the
first...

this is my code to start..

this way i can enter a letter and get a hirana equivalent
but when it happens the program stops!


class Test
  def initialize
    vowels = Hash['a'=>'あ', 'i'=>'い', 'u'=>'う', 'e'=>'え', 'o'=>'お']
    letter = gets.chomp.downcase
    # logic here
    case letter
    when 'a'
      print "#{vowels['a']}"
    when 'i'
      print "#{vowels['i']}"
    when 'u'
      print "#{vowels['u']}"
    when 'e'
      print "#{vowels['e']}"
    when 'o'
      print "#{vowels['o']}"
    else
      puts "This letter is not part of hiragana alphabet!"
    end
  end
end

t = Test.new

Cristiano de Araujo Bezerra

unread,
Apr 16, 2015, 10:50:21 AM4/16/15
to rubyonra...@googlegroups.com
i found almost what i was looking for:

class Test2
  def initialize
    vowels = Hash['a'=>'あ', 'i'=>'い', 'u'=>'う', 'e'=>'え', 'o'=>'お']


    letter = gets.chomp.downcase

    while letter != 'q'
      if letter == 'a'
        print "#{vowels['a']}"
        letter = gets.chomp.downcase
      elsif letter == 'i'
        print "#{vowels['i']}"
        letter = gets.chomp.downcase
      elsif letter == 'u'
        print "#{vowels['u']}"
        letter = gets.chomp.downcase
      elsif letter == 'e'
        print "#{vowels['e']}"
        letter = gets.chomp.downcase
      elsif letter == 'o'
        print "#{vowels['o']}"
        letter = gets.chomp.downcase
      else
        puts "This letter is not part of hiragana alphabet!"
        break
      end
    end
  end
end

t2 = Test2.new

Cristiano de Araujo Bezerra

unread,
Apr 16, 2015, 9:58:47 PM4/16/15
to rubyonra...@googlegroups.com
thanks for attention i found a way to solve my problem:

true
vowels = {'a'=>'あ', 'i'=>'い', 'u'=>'う', 'e'=>'え', 'o'=>'お'}
key = nil
while(key != "q") do
  key = gets.chomp
  case key
  when 'a'
    print "#{vowels['a']}"
  when 'i'
    print "#{vowels['i']}"
  when 'u'
    print "#{vowels['u']}"
  when 'e'
    print "#{vowels['e']}"
  when 'o'
    print "#{vowels['o']}"
  when 'q'
    puts 'bye bye'
  when ''
    puts 'No letter was typed!'
  else
    puts "This letter is not part of hiragana alphabet!"
  end
end

botp

unread,
Apr 17, 2015, 6:06:08 AM4/17/15
to rubyonra...@googlegroups.com
On Fri, Apr 17, 2015 at 9:58 AM, Cristiano de Araujo Bezerra
<webo...@gmail.com> wrote:
> case key
> when 'a'
> print "#{vowels['a']}"
> when 'i'
> print "#{vowels['i']}"
> when 'u'
> print "#{vowels['u']}"
> when 'e'
> print "#{vowels['e']}"
> when 'o'
> print "#{vowels['o']}"
> when 'q'
> puts 'bye bye'
> when ''
> puts 'No letter was typed!'
> else
> puts "This letter is not part of hiragana alphabet!"
> end

you may replace the above case statement w

vowel = vowels[key] || "this letter is not part of hiragana alphabet\n"
print vowel

kind regards --botp

Cristiano de Araujo Bezerra

unread,
Apr 18, 2015, 1:27:30 AM4/18/15
to rubyonra...@googlegroups.com


--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-talk/q-7s5NpHTn0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAAwHHQg2BvS4i8LthOD7Kf0nO79%2BL3rVP%2B8pAGcKjZ7AajwKsA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
      Cristiano Carvalho
     
   

10101010101.' .`.\._0 0 _.|._ 1 1_./.`. '.0101010101010101010
01010101. ' .' . .\._` ` _|_ ` `_./. . '. ' .0101010101010101
 _1.1- ' . ' .' . .\._` ` | ` `_./. . '. ' . ` -0.0_010101010
`-._. - ` . ' .' . .\._` `|` `_./. . '. ' . ` - ._.-'01010101
    `-._ ` . ' .' . .\._` | `_./. . '. ' . ` _.-'   010101010
        `-._. ' .' . .\._`|`_./. . '. ' ._.-'        01010101
            `-._ .' . .\._|_./. . '. _.-'             0101010
                `-.____.\.|./.____.-'                  010101
                 _/_/__\_\|/_/__\_\_                     1010
________________/.--##/#//-\\#\##--.\_______________________1
               // \##{-(@)=(@)-}##/ \\                      0
              || _.-'.\-\VVV/-/.`-._ ||                  0101
             _|-'_ . -./--|--\.- .- `-|_               101010
         _.-'' -_ . -./.- | -.\.- .- _- `-._          1010101
     _.-',  ' -_ . -./.- `|` -.\.- .- _- `  `-._     10101010
 _.-' . ,  ' -_ . -./.- ` | ` -.\.- .- _- `  , .`-._101010101
'0 - . ,  ' -_ . -./.- ` `|` ` -.\.- .- _- `  , . -1`10101010
010101010'0-_ . -./.- ` ` | ` ` -.\.- .- _-0`0101010101010101
1010101010101. -./.- ` ` -|- ` ` -.\.- .-10101010101010101010
01010101010101-./.-1`1`1-.|.-0`0`0-.\.-0101010101010101010101
10101010101010101010101010|1010101010101010101010101010101010
Reply all
Reply to author
Forward
0 new messages