Class: ScribeDb::Model::Scribe

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/scribelite/models/scribe.rb,
lib/scribelite/models/forward.rb

Class Method Summary collapse

Class Method Details

.avifObject



24
# File 'lib/scribelite/models/scribe.rb', line 24

def self.avif() where( content_type: 'image/avif' ); end

.block_countsObject Also known as: counts_by_block



104
105
106
107
# File 'lib/scribelite/models/scribe.rb', line 104

def self.block_counts
    joins(:tx).group( 'block' )
      .order( 'block').count
end

.block_with_timestamp_countsObject Also known as: counts_by_block_with_timestamp



109
110
111
112
# File 'lib/scribelite/models/scribe.rb', line 109

def self.block_with_timestamp_counts
    joins(:tx).group( Arel.sql( "block || ' @ ' || date" ))
      .order( 'block' ).count
end

.content_type_countsObject Also known as: counts_by_content_type



98
99
100
101
# File 'lib/scribelite/models/scribe.rb', line 98

def self.content_type_counts
    group( 'content_type' )
    .order( Arel.sql( 'COUNT(*) DESC, content_type')).count
end

.date_countsObject Also known as: counts_by_date, counts_by_day



115
116
117
118
119
# File 'lib/scribelite/models/scribe.rb', line 115

def self.date_counts
   ## note: strftime is SQLite specific/only!!!

   joins(:tx).group( Arel.sql("strftime('%Y-%m-%d', date)"))
    .order( Arel.sql("strftime('%Y-%m-%d', date)")).count
end

.from_countsObject Also known as: counts_by_address



140
141
142
143
144
145
# File 'lib/scribelite/models/scribe.rb', line 140

def self.from_counts
 ## note: from is sql keyword!!!

 ##  wrap in [] for sqlite - check if works for others!!!  

   joins(:tx).group( '[from]' )
    .order( Arel.sql( 'COUNT(*) DESC')).count
end

.gifObject



19
# File 'lib/scribelite/models/scribe.rb', line 19

def self.gif() where( content_type: 'image/gif' ); end

.hour_countsObject Also known as: counts_by_hour



133
134
135
136
137
# File 'lib/scribelite/models/scribe.rb', line 133

def self.hour_counts
  ## note: strftime is SQLite specific/only!!!

   joins(:tx).group( Arel.sql("strftime('%Y-%m-%d %Hh', date)"))
   .order( Arel.sql("strftime('%Y-%m-%d %Hh', date)")).count
end

.htmlObject



43
44
45
46
47
48
# File 'lib/scribelite/models/scribe.rb', line 43

def self.html
    where( content_type: [
       'text/html;charset=utf-8',
       'text/html',
      ])
end

.imageObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/scribelite/models/scribe.rb', line 30

def self.image  
     ## change to/or add alias e.g. image/images - why? why not

    where( content_type: [
        'image/png',
        'image/jpeg',
        'image/jpg',
        'image/gif',
        'image/webp',
        'image/svg+xml',
        'image/avif',
        ])
end

.jpgObject Also known as: jpeg



20
21
# File 'lib/scribelite/models/scribe.rb', line 20

def self.jpg() where( content_type: ['image/jpeg',
'image/jpg'] ); end

.jsObject Also known as: javascript



50
51
52
53
54
55
# File 'lib/scribelite/models/scribe.rb', line 50

def self.js
    where( content_type: [
       'text/javascript',
       'application/javascript',
      ])
end

.largestObject Also known as: biggest



94
95
96
# File 'lib/scribelite/models/scribe.rb', line 94

def self.largest
   order( 'bytes DESC' )
end

.month_countsObject Also known as: counts_by_month



121
122
123
124
125
# File 'lib/scribelite/models/scribe.rb', line 121

def self.month_counts
   ## note: strftime is SQLite specific/only!!!

   joins(:tx).group( Arel.sql("strftime('%Y-%m', date)"))
    .order( Arel.sql("strftime('%Y-%m', date)")).count
end

.pngObject

scope like helpers



18
# File 'lib/scribelite/models/scribe.rb', line 18

def self.png() where( content_type: 'image/png' ); end

.sub100kObject



86
# File 'lib/scribelite/models/scribe.rb', line 86

def self.sub100k()  where( 'num < 100000' ); end

.sub10kObject



84
# File 'lib/scribelite/models/scribe.rb', line 84

def self.sub10k()  where( 'num < 10000' ); end

.sub10mObject



89
# File 'lib/scribelite/models/scribe.rb', line 89

def self.sub10m()  where( 'num < 10000000' ); end

.sub1kObject

def self.search( q ) ## “full-text” search helper

    ##  rename to text_search - why? why not?        
    ## auto-sort by num - why? why not?
    joins(:blob).text.where( "content LIKE '%#{q}%'" ).order('num')
end


82
# File 'lib/scribelite/models/scribe.rb', line 82

def self.sub1k()  where( 'num < 1000' ); end

.sub1mObject



87
# File 'lib/scribelite/models/scribe.rb', line 87

def self.sub1m()  where( 'num < 1000000' ); end

.sub20kObject



85
# File 'lib/scribelite/models/scribe.rb', line 85

def self.sub20k()  where( 'num < 20000' ); end

.sub20mObject



90
# File 'lib/scribelite/models/scribe.rb', line 90

def self.sub20m()  where( 'num < 20000000' ); end

.sub21mObject



91
# File 'lib/scribelite/models/scribe.rb', line 91

def self.sub21m()  where( 'num < 21000000' ); end

.sub2kObject



83
# File 'lib/scribelite/models/scribe.rb', line 83

def self.sub2k()  where( 'num < 2000' ); end

.sub2mObject



88
# File 'lib/scribelite/models/scribe.rb', line 88

def self.sub2m()  where( 'num < 2000000' ); end

.svgObject



23
# File 'lib/scribelite/models/scribe.rb', line 23

def self.svg()  where( content_type: 'image/svg+xml' ); end

.textObject



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/scribelite/models/scribe.rb', line 61

def self.text
    ## change to/or add alias e.g. text/texts - why? why not

    ## include html or svg in text-only inscription - why? why not?

    ##  include markdown in text-only inscription - why? why not?

    ##   make content_type lower case with lower() - why? why not?

    where( content_type: [
              'text/plain',
              'text/plain;charset=utf-8',
              'text/plain;charset=us-ascii',
              'application/json',
         ])
end

.webpObject



22
# File 'lib/scribelite/models/scribe.rb', line 22

def self.webp() where( content_type: 'image/webp' ); end

.year_countsObject Also known as: counts_by_year



127
128
129
130
131
# File 'lib/scribelite/models/scribe.rb', line 127

def self.year_counts
   ## note: strftime is SQLite specific/only!!!

   joins(:tx).group( Arel.sql("strftime('%Y', date)"))
    .order( Arel.sql("strftime('%Y', date)")).count
end