Module: Flumtter::Util
- Included in:
- Client, Command::User, Command::UserList, Keyboard, TimeLine::Base, Window::Buf::Element, Window::Buf::Screen
- Defined in:
- lib/flumtter/app/core/util.rb
Instance Method Summary collapse
- #command_value_regexp(command) ⇒ Object
- #dialog_for_index(title, body, with_screen_name = false) ⇒ Object
- #error(e) ⇒ Object
- #error_handler ⇒ Object
- #id2obj(id) ⇒ Object
- #if_tweet(obj, twitter) ⇒ Object
- #index_regexp ⇒ Object
- #index_with_dialog(m, title, body, with_screen_name = false) ⇒ Object
- #logger ⇒ Object
- #on_event(*args, &blk) ⇒ Object
- #parse_index(text, with_screen_name = false) ⇒ Object
- #parse_time(time) ⇒ Object
- #sarastire(*args) ⇒ Object
- #sarastire_user(*args) ⇒ Object
- #screen_name_regexp ⇒ Object
Instance Method Details
#command_value_regexp(command) ⇒ Object
67 68 69 |
# File 'lib/flumtter/app/core/util.rb', line 67 def command_value_regexp(command) /^#{command}[ | ]*(.*)/ end |
#dialog_for_index(title, body, with_screen_name = false) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/flumtter/app/core/util.rb', line 38 def dialog_for_index(title, body, with_screen_name=false) dialog = Window::Dialog.new(title, body) dialog.command(index_regexp) do |m| [id2obj(m[1]), m[2]] end if with_screen_name dialog.command(screen_name_regexp) do |m| [m[1], m[2]] end end dialog.show(true, false) end |
#error(e) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/flumtter/app/core/util.rb', line 7 def error(e) text = <<~EOF #{e.backtrace.shift}: #{e.} (#{e.class}) #{e.backtrace.join("\n")} EOF e.class.ancestors.include?(StandardError) ? logger.error(text) : logger.fatal(text) print text.color(Setting[:color][:error]) end |
#error_handler ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/flumtter/app/core/util.rb', line 71 def error_handler begin yield rescue IndexError Window::Popup::Error.new("Please select correct index.").show rescue UnSupportError puts "This object is unsupported.".color rescue ExecutedError => e text = e..empty? ? "The operation is already executed." : e. print text.dnl.color(:cyan) rescue NoContentError puts "Please input content.".color rescue Twitter::Error::NotFound => e puts e..color rescue Twitter::Error::Unauthorized => e puts e..color rescue Twitter::Error::Forbidden => e puts e..color end end |
#id2obj(id) ⇒ Object
32 33 34 35 36 |
# File 'lib/flumtter/app/core/util.rb', line 32 def id2obj(id) obj = TimeLine::Base[id.to_i] raise IndexError if obj.nil? obj end |
#if_tweet(obj, twitter) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/flumtter/app/core/util.rb', line 92 def if_tweet(obj, twitter) case obj when Twitter::Tweet yield(obj) when Twitter::Streaming::Event type = obj.type(twitter) if type.include?(:favorite) || type.include?(:unfavorite) yield(obj.target_object) else raise UnSupportError end else raise UnSupportError end end |
#index_regexp ⇒ Object
59 60 61 |
# File 'lib/flumtter/app/core/util.rb', line 59 def index_regexp /^(\d+)[ | ]*(.*)/ end |
#index_with_dialog(m, title, body, with_screen_name = false) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/flumtter/app/core/util.rb', line 51 def index_with_dialog(m, title, body, with_screen_name=false) if m.empty? dialog_for_index(title, body, with_screen_name) else parse_index(m, with_screen_name) end end |
#logger ⇒ Object
108 109 110 |
# File 'lib/flumtter/app/core/util.rb', line 108 def logger Flumtter.logger end |
#on_event(*args, &blk) ⇒ Object
120 121 122 |
# File 'lib/flumtter/app/core/util.rb', line 120 def on_event(*args,&blk) Flumtter.on_event(*args,&blk) end |
#parse_index(text, with_screen_name = false) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/flumtter/app/core/util.rb', line 21 def parse_index(text, with_screen_name=false) if m = text.match(index_regexp) obj = id2obj(m[1]) return obj, m[2] end if with_screen_name && m = text.match(screen_name_regexp) return m[1], m[2] end raise IndexError end |
#parse_time(time) ⇒ Object
17 18 19 |
# File 'lib/flumtter/app/core/util.rb', line 17 def parse_time(time) time.getlocal.strftime("%Y/%m/%d %H:%M:%S") end |
#sarastire(*args) ⇒ Object
112 113 114 |
# File 'lib/flumtter/app/core/util.rb', line 112 def sarastire(*args) Flumtter.sarastire(*args) end |
#sarastire_user(*args) ⇒ Object
116 117 118 |
# File 'lib/flumtter/app/core/util.rb', line 116 def sarastire_user(*args) Flumtter.sarastire_user(*args) end |
#screen_name_regexp ⇒ Object
63 64 65 |
# File 'lib/flumtter/app/core/util.rb', line 63 def screen_name_regexp /^([@|@]*[A-Za-z0-9_]{1,15})[ | ]*(.*)/ end |