Class: TwitterAutoPoster::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



7
8
9
# File 'lib/parser.rb', line 7

def initialize
  @words=Array.new
end

Instance Attribute Details

#wordsObject

Returns the value of attribute words.



5
6
7
# File 'lib/parser.rb', line 5

def words
  @words
end

Class Method Details

.parse_command(command, user) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/parser.rb', line 21

def self.parse_command(command, user)
  case command
    when "-help"
      puts HELP
    when "-sm"
      puts TwitterAutoPoster::Phrases::ASKING_FOR_MESSAGE
      message=gets.chomp
      user.send_message(message)
    when "-smff"
      puts TwitterAutoPoster::Phrases::ASKING_FOR_FILE_PATH
      path=gets.chomp
      user.send_messages_from_file(path)
    when "-set ml"
      puts TwitterAutoPoster::Phrases::ASKING_FOR_MESSAGE_LENGTH
      length=gets.chomp
      user.message_length=length
    when "-set sep"
      puts TwitterAutoPoster::Phrases::ASKING_FOR_SEPARATOR
      separator=gets.chomp
      user.separator=separator

    when "-exit"
      return "-exit"
    else
      raise Exception.new(UNKNOWN_COMMAND+" \""+command+"\"")
  end
  SUCCESS
end

Instance Method Details

#parse_file(str) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/parser.rb', line 11

def parse_file(str)
  if validate_file(str)
    text = File.open(str, 'r') { |file| file.read }
    @words=words_from_text(text)
  else
    raise Exception.new(FILE_IS_NOT_VALID)
  end

end