imsg 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/imsg.rb +53 -21
  4. data/lib/imsg/version.rb +1 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a81a94e2ace83d8ccc93b41b0f081aaebc8eab97
4
- data.tar.gz: 6b243ee65b0bd53c88b7bc1c59116059b939dc42
3
+ metadata.gz: ebc7fd076a7c56ab0d450077012b0aa36f9cccc8
4
+ data.tar.gz: bd23220b3346f311046c51e078b5b32c5420e621
5
5
  SHA512:
6
- metadata.gz: 68fe23cc2f81337e01243412ed5aaabf5bb48156d4575fc94c346e9a50316f9a1cfdd62a1e3ee5d9e201e8660a03c262877bf54fb0caaa3c306b26c1dfd36207
7
- data.tar.gz: 4aaf1e3c6fb502cebd810aea86bb4393eb2df6b9a6a54450dee5cce33e39248b43571743533370cf2f4a3e73d07e359dd038eafcf074f7094237c0c85922041f
6
+ metadata.gz: 68d1ec0492b62487b8d105569d877c211a15306bb3a6147ffcd12e465c0b59f3a00bd717f71ef087d4ac39b0be7aceb3c1fedec58334869045215c7568cf6ee6
7
+ data.tar.gz: 68409ec4ef8c10663ebf8c1bfdbbfaf6d952e72149fb6adab6f1080b9d07252d62febbe8048dd2c0991d5371699a9f0efb44b78cfb41601a1277b46ac22438b7
data/README.md CHANGED
@@ -32,7 +32,7 @@ $ 4
32
32
  ```
33
33
 
34
34
  ## Common problems
35
- ###Using special characters
35
+ ###Using special characters:
36
36
  If you wanna use special characters like parentheses, brackets or quotes you need to escape it. i.e.:
37
37
  ```bash
38
38
  $ imsg HELLOOO FROM TERMINAL \(ESCAPIIING\)
data/lib/imsg.rb CHANGED
@@ -3,17 +3,58 @@ require "imsg/version"
3
3
  require 'appscript'
4
4
 
5
5
  module ImsgHandler
6
+ CHAT_DISPLAY_LIMIT = 12
6
7
 
7
- # Formats a list of buddies objects retrieved by Applescript into a readable list
8
- # returns a formatted String
9
- def self.formatBuddies buddies
10
- formatedString = ""
11
- count = 1
12
- buddies.each do |buddy|
13
- formatedString += " " + count.to_s + " - " + buddy.join(',') + "\n"
14
- count += 1
8
+ class Chat
9
+ attr_accessor :chat_number, :updated, :participants
10
+
11
+ def initialize(chat_number, updated, participants)
12
+ self.chat_number = chat_number
13
+ self.updated = updated
14
+ self.participants = participants
15
+ end
16
+
17
+ def to_s
18
+ "#{chat_number} - #{participants.map(&:name).join(", ")}"
19
+ end
20
+
21
+ def self.fetch_all
22
+ ascript_chats.map.with_index(1){ |chat, i| from_ascript_chat(chat, i) }
23
+ end
24
+
25
+ def self.ascript_chats
26
+ Appscript.app("Messages").chats.get()
27
+ end
28
+
29
+ def self.from_ascript_chat(chat, chat_number)
30
+ new(chat_number, chat.updated.get(), participants_from_ascript_chat(chat))
31
+ end
32
+
33
+ def self.participants_from_ascript_chat(chat)
34
+ chat.participants.get().map do |participant|
35
+ Participant.from_ascript_participant(participant)
36
+ end
15
37
  end
16
- formatedString
38
+ end
39
+
40
+ class Participant
41
+ attr_accessor :name
42
+
43
+ def initialize(name)
44
+ self.name = name
45
+ end
46
+
47
+ def self.from_ascript_participant(ascript_participant)
48
+ self.new(ascript_participant.name.get())
49
+ end
50
+ end
51
+
52
+ def self.display_chats(chats)
53
+ sort_by_updated(chats).first(CHAT_DISPLAY_LIMIT).map(&:to_s).join("\n")
54
+ end
55
+
56
+ def self.sort_by_updated(chats)
57
+ chats.sort{ |a, b| b.updated <=> a.updated }
17
58
  end
18
59
 
19
60
  # Check if a String is a integer number
@@ -35,19 +76,10 @@ module ImsgHandler
35
76
 
36
77
  # Shows the chat list along with their participants
37
78
  def self.showChatList
38
- imsg = Appscript.app("Messages")
39
- participants = imsg.chats.participants.get()
40
- participantsByChat = []
41
- participants.each do |v|
42
- names = []
43
- v.each do |buddy|
44
- names.push buddy.name.get()
45
- end
46
- participantsByChat.push names
47
- end
79
+ chats = Chat.fetch_all
48
80
  puts "\nWho would you like to send your message to?"
49
81
  puts "(You can choose a number or type a buddy name/email)\n\n"
50
- puts formatBuddies participantsByChat
82
+ puts display_chats(chats)
51
83
  end
52
84
 
53
- end
85
+ end
data/lib/imsg/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Imsg
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imsg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sampaio