Method: Alien::AlienTag#create
- Defined in:
- lib/alien/alientag.rb
#create(taglist_entry) ⇒ Object
Try to parse a taglist entry into a set of Tag object variables.
Uses a simple mapping from Alien ‘text’ format:
Tag:0102 0304 0506 0708 0900 0A0B, Disc:2008/10/28 10:49:35, Last:2008/10/28 10:49:35, Count:1, Ant:3, Proto:2
rssi and speed attributes are not included in the default text format. In order to have them parsed correctly the TagListFormat must be set to custom and the TagListCustomFormat fields must be separated by the following text tokens:
'tag:', 'disc:', 'last:', 'count:', 'ant:', 'proto:', 'speed:', 'rssi:'
For example:
@rdr.taglistcustomformat("Tag:%i, Disc:${DATE1} ${TIME1}, Last:${DATE2} ${TIME2}, Count:${COUNT}, Ant:${TX}, Proto:${PROTO#}, Speed:${SPEED}, rssi:${RSSI})"
@rdr.taglistformat("custom")
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/alien/alientag.rb', line 89 def create(taglist_entry) @id = "" return self if (taglist_entry=="(No Tags)") tagline = taglist_entry.split("\r\n")[0] tagbits = Hash.new("0") tagline.split(", ").each do |keyval| key, val = keyval.split(":", 2) if key.nil? raise "Trouble parsing taglist string. Text format expected. This string was: #{taglist_entry}" end tagbits[key.downcase] = val end if (!tagbits.empty?) #zero length ids can cause funny behavior if tagbits['tag'] != nil @id = tagbits['tag'] end @ant = tagbits['ant'] @count = tagbits['count'] @disc = tagbits['disc'] @last = DateTime.parse(tagbits['last']) @last_last = @last @proto = tagbits['proto'] @rssi = tagbits['rssi'] @freq = tagbits['freq'] @speed = tagbits['speed'] end return self end |